[SOLVED] Running .exe from another cmd prompt not working properly.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PAB
Posts: 139
Joined: 12 Aug 2019 13:57

[SOLVED] Running .exe from another cmd prompt not working properly.

#1 Post by PAB » 03 Oct 2019 12:30

Good evening everyone!

I have a FileName.exe file on the desktop. OK so far.
I have a script that runs and then opens another cmd prompt and runs the FileName.exe on the desktop. OK so far.
While the FileName.exe is running there is some user [key presses] interaction. OK so far.
The final interaction involves pressing any key which closes the cmd prompt window and opens a Notepad file. OK so far.
Whereby I am back in my original cmd prompt window. OK so far.

What I would like the code to do, and I just can't seem to fathom it out (I have tried many many variations), is when the FileName.exe has finished and the cmd prompt windows closes (after pressing any key to exit), I would like it to kill the Notepad file and show the message FileName.exe has completed successfully! and then show < Press ANY key to CONTINUE >. Whereby the rest of might script will continue to run!

Here is the code . . .

Code: Select all

@echo off
echo Running SFCFix . . .
echo.
start "" "%userprofile%\Desktop\FileName.exe" /secondary /minimized
echo ^< Press ANY key to CONTINUE ^> & Pause > NUL
taskkill /IM Notepad.exe > NUL
echo.
echo FileName.exe has completed successfully!
echo.
At the moment, the only way I can get the script to work (I have jiggled it every which way without success) is to close the cmd prompt window that runs the FileName.exe (/secondary /minimized), and then < Press ANY key to CONTINUE > which then kills Notepad and displays the message FileName.exe has completed successfully!

Thanks in advance.
Last edited by PAB on 07 Nov 2019 09:32, edited 1 time in total.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Running .exe from another cmd prompt not working properly.

#2 Post by aGerman » 03 Oct 2019 12:54

If you don't want to run FileName.exe asynchronously, why do you use START rather than CALL? Or at least use START /WAIT.

Steffen

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Running .exe from another cmd prompt not working properly.

#3 Post by PAB » 03 Oct 2019 12:59

Sorry, I don't follow what you mean!

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Running .exe from another cmd prompt not working properly.

#4 Post by aGerman » 03 Oct 2019 13:08

You want to do something "when the FileName.exe has finished". But the script doesn't wait for the FileName.exe process if you use the START command. The script just continues with the next line regardless whether or not FileName.exe still runs. My conclusion was that you need to run FileName.exe synchronously. In that case your script would only continue if FileName.exe has finished.

Steffen

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Running .exe from another cmd prompt not working properly.

#5 Post by PAB » 03 Oct 2019 13:21

Thanks for the reply, it is appreciated.

The script does actually wait for the FileName.exe to finish because I use echo ^< Press ANY key to CONTINUE ^> & Pause > NUL, so that isn't the problem. When any key is pressed the the script continues to run!

What I would like is, when the FileName.exe has finished and the cmd prompt windows closes (after pressing any key to exit), which it actually does do, I would like it to immediately kill the Notepad file which gets generated when it closes, and then show the message FileName.exe has completed successfully!

Then I should be back at my original cmd prompt window with < Press ANY key to CONTINUE >, which when pressed will continue running my original script.

Thanks in advance.

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Running .exe from another cmd prompt not working properly.

#6 Post by PAB » 04 Oct 2019 01:28

Cracked it! . . .

Code: Select all

echo Running FileName.exe . . .
start /w "" "%userprofile%\Desktop\FileName.exe" /secondary /minimized
taskkill /IM Notepad.exe > NUL
echo FileName.exe has completed successfully!
. . . and then the rest of the code doesn't start running in the original cmd prompt until the cmd prompt window running the FileName.exe has finished. Therefore I can also do without using the echo ^< Press ANY key to CONTINUE ^> & Pause > NUL as well!

One point though please.

If I close the cmd prompt window that opens with start /w "" "%userprofile%\Desktop\FileName.exe" /secondary /minimized then in the original cmd prompt window I receive Terminate batch job <Y/N>?. I have to physically enter N and Enter for the code in the original cmd window to continue running.

Is there a way I can . . .

[1] Ignore the message (hide it) and continue running the code in the original cmd window (I tried 2>NUL but it doesn't work)?

[2] Not have the message Terminate batch job <Y/N>? show in the original cmd prompt window but have a message saying FileName.exe aborted, continuing . . .. In other words, replace Terminate batch job <Y/N>? with FileName.exe aborted, continuing . . .? It will be like an error trap. If the FileName.exe runs to completion then the message FileName.exe has completed successfully! appears, but if the cmd window is closed, then the message FileName.exe aborted, continuing . . . appears instead.

Sorry number 2 is a bit convoluted but I was just trying to make it clear!

Thanks in advance.

EDIT: Number 2 is NOT important, I just added a message to NOT CLOSE THE CMD WINDOW!

BUT, number 1 would be nice to figure out!

PAB
Posts: 139
Joined: 12 Aug 2019 13:57

Re: Running .exe from another cmd prompt not working properly.

#7 Post by PAB » 06 Oct 2019 05:53

Not to worry.
I got round it by putting a message saying NOT to close the cmd prompt window.
Thanks aGerman for the help anyway , it is appreciated.

Post Reply