windows 如何运行 .exe 但保持在同一个命令窗口中(而不是打开一个新窗口)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9583880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:18:59  来源:igfitidea点击:

How do I run a .exe but stay in the same command window (not open a new one)?

windowsbatch-filecmd

提问by Oliver Bennett

I have searched for many weeks to solve my problem and can't find a good way of doing it that works on every machine I may need to use.

我已经搜索了好几个星期来解决我的问题,但找不到一种适用于我可能需要使用的每台机器的好方法。

I know START command opens a new window to do the .exe, but I want to stay in the same window and run the .exe

我知道 START 命令会打开一个新窗口来执行 .exe,但我想留在同一个窗口中并运行 .exe

(because I want my batch file to continue ONLY WHEN THE .EXE has finished running)

(因为我希望我的批处理文件仅在 .EXE 完成运行时继续)

I have found that on some computers when I .exe it opens a new window and other computers is stays in the same window which makes me think my code is fine but there is a setting somewhere on the computers that is different.

我发现在某些计算机上,当我打开 .exe 时它会打开一个新窗口,而其他计算机则停留在同一个窗口中,这让我认为我的代码很好,但计算机上某处的设置不同。

Can you help? What are my options? The .exe I am running is NASTRAN which is an engineering solver that runs in command window.

你能帮我吗?我有哪些选择?我正在运行的 .exe 是 NASTRAN,它是一个在命令窗口中运行的工程求解器。

采纳答案by TheBlastOne

You probably have a different variant of the .exe on some machines which is called only there, and spawns a separate window, for reasons I cannot know. Search for the .exe file on all machines and compare.

您可能在某些机器上有一个不同的 .exe 变体,它只在那里被调用,并产生一个单独的窗口,原因我不知道。在所有机器上搜索 .exe 文件并进行比较。

Also, post your batch file code so we can exactly see how you start the .exe.

另外,发布您的批处理文件代码,以便我们可以准确地了解您如何启动 .exe。

回答by Cyclonecode

To wait for the command to terminate you should use the WAITflag:

要等待命令终止,您应该使用以下WAIT标志:

start /WAIT c:/windows/system32/notepad.exe

You could start an application without creating a new window using the Bflag:

您可以使用以下B标志在不创建新窗口的情况下启动应用程序:

start /WAIT /B "c:/windows/system32/cmd.exe"

You should also try reading the help text for the start command:

您还应该尝试阅读 start 命令的帮助文本:

start /?

回答by stefanbc

You can use cmd /k example.exe

您可以使用 cmd /k example.exe

回答by anhoppe

You could consider not using startat all. Simply start the executable directly.

您可以考虑根本不使用 start。直接启动可执行文件即可。

回答by Gokulrams

Did you try using call in the batch file. it runs the exe in the same window. as the batch file. The next statement in the batch file is executed after this exe is finished running

您是否尝试在批处理文件中使用调用。它在同一窗口中运行 exe。作为批处理文件。这个exe运行完毕后执行批处理文件中的下一条语句