Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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.

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

like image 267
Oliver Bennett Avatar asked Mar 06 '12 12:03

Oliver Bennett


People also ask

Can you run an EXE file from Command Prompt?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

Can you run 2 command prompts at once?

Click Start, type cmd, and press Enter to open a command prompt window. In the Windows taskbar, right-click the command prompt window icon and select Command Prompt. A second command prompt window is opened.

How do I run a batch file without closing a window?

If you're creating a batch file and want the MS-DOS window to remain open, add PAUSE to the end of your batch file. This prompts the user to Press any key. Until the user presses any key, the window remains open instead of closing automatically.


4 Answers

To wait for the command to terminate you should use the WAIT flag:

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

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

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

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

start /? 
like image 78
Cyclonecode Avatar answered Oct 06 '22 01:10

Cyclonecode


You can use cmd /k example.exe

like image 33
stefanbc Avatar answered Oct 06 '22 00:10

stefanbc


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.

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

like image 25
TheBlastOne Avatar answered Oct 06 '22 02:10

TheBlastOne


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

like image 43
anhoppe Avatar answered Oct 06 '22 00:10

anhoppe