Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Samir
- Posts: 384
- Joined: 16 Jul 2013 12:00
- Location: HSV
-
Contact:
#1
Post
by Samir » 30 Oct 2015 10:23
I've read several thread on running two applications simultaneously and then waiting for both to end before moving on to the next step. My application is a bit easier and I think there may be a way to just do it using START /W.
I've got this so far:
Code: Select all
START NOTEPAD BAT00000678.RPT
START /W NOTEPAD BAT00000875.RPT
ECHO DONE EDITING
This will allow the batch continue when the second notepad is closed, but if the user accidentally closes it first, the batch will think the editing is done on both.
What I want to do is somehow execute both commands on one 'START /W'. Possible?
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 30 Oct 2015 11:15
Samir wrote:but if the user accidentally closes it first, the batch will think the editing is done on both.
I am not getting that result at all. If I close the first instance of Notepad my batch file it still waiting for the second instance to close before the batch file continues.
You will also find out that many programs do not respect the /WAIT option from the START command.
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#3
Post
by penpen » 30 Oct 2015 11:44
On my winxp and win 8.1 i can confirm that the bach continues, when closing the second one first.
You have no output, so you could use:
Code: Select all
@echo off
NOTEPAD BAT00000678.RPT | NOTEPAD BAT00000875.RPT
ECHO DONE EDITING
penpen
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 30 Oct 2015 11:54
I think I misunderstood his wording. I thought he meant if the first one was closed, the batch file will continue.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#5
Post
by Squashman » 30 Oct 2015 12:00
I am pretty sure we have had lengthy discussions about this topic in another thread but I can't find it.
In this instance you could check the verbose output of TASKLIST to see what files NOTEPAD.EXE has open.
Code: Select all
C:\BatchFiles>tasklist /v |find /i "notepad.exe"
notepad.exe 1196 Console 1 7,644 K Running NA\Squash 0:00:00 temp1.txt - Notepad
notepad.exe 5568 Console 1 7,644 K Running NA\Squash 0:00:00 temp2.txt - Notepad
Of course this probably doesn't help with other applications. And of course you could in theory start a third instance of notepad with one of those files being opened.
Code: Select all
C:\BatchFiles>tasklist /v |find /i "notepad.exe"
notepad.exe 1196 Console 1 7,644 K Running NA\Squash 0:00:00 temp1.txt - Notepad
notepad.exe 5568 Console 1 7,644 K Running NA\Squash 0:00:00 temp2.txt - Notepad
notepad.exe 7032 Console 1 7,236 K Running NA\Squash 0:00:00 temp1.txt - Notepad
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#6
Post
by penpen » 30 Oct 2015 12:32
Squashman wrote:I am pretty sure we have had lengthy discussions about this topic in another thread but I can't find it.
I've found this:
http://www.dostips.com/forum/viewtopic.php?f=3&t=5598.
(I assume you meant another thread, because while posting to the linked topic i had that feeling, too. But i cannot find another.)
penpen
-
Samir
- Posts: 384
- Joined: 16 Jul 2013 12:00
- Location: HSV
-
Contact:
#7
Post
by Samir » 30 Oct 2015 13:24
Squashman wrote:Samir wrote:but if the user accidentally closes it first, the batch will think the editing is done on both.
I am not getting that result at all. If I close the first instance of Notepad my batch file it still waiting for the second instance to close before the batch file continues.
You will also find out that many programs do not respect the /WAIT option from the START command.
Sorry, meant closing the second. Notepad seems to work pretty well. Have you seen it misbehave?
-
Samir
- Posts: 384
- Joined: 16 Jul 2013 12:00
- Location: HSV
-
Contact:
#8
Post
by Samir » 30 Oct 2015 13:27
Sorry everyone, I meant the second can be closed and the batch will continue with the first file program open.
I've also read that thread penpen, hence why I'm looking for an easier way to do this if possible as that much code would be overkill.
-
Samir
- Posts: 384
- Joined: 16 Jul 2013 12:00
- Location: HSV
-
Contact:
#9
Post
by Samir » 30 Oct 2015 13:29
penpen wrote:On my winxp and win 8.1 i can confirm that the bach continues, when closing the second one first.
You have no output, so you could use:
Code: Select all
@echo off
NOTEPAD BAT00000678.RPT | NOTEPAD BAT00000875.RPT
ECHO DONE EDITING
penpen
This seems to work!
Try it:
Code: Select all
@echo off
START /W NOTEPAD BAT00000678.RPT | NOTEPAD BAT00000875.RPT
ECHO DONE EDITING
I have to close both instances of notepad for it to continue.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#10
Post
by Squashman » 30 Oct 2015 13:38
This seems to work as well.
Code: Select all
@echo off
start "" /wait cmd /c temp.bat |start "" /wait cmd /c temp2.bat
echo all done
pause
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#11
Post
by penpen » 30 Oct 2015 13:42
I don't see the benefit of using "start /W" when using pipes, especially if you want to keep it simple.
The batch already waits all called threads to close before continuing with the next line.
penpen
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#12
Post
by Squashman » 30 Oct 2015 13:51
penpen wrote:I don't see the benefit of using "start /W" when using pipes, especially if you want to keep it simple.
The batch already waits all called threads to close before continuing with the next line.
penpen
Now you are confusing me. You just said this.
penpen wrote:On my winxp and win 8.1 i can confirm that the bach continues, when closing the second one first.
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#13
Post
by penpen » 30 Oct 2015 13:59
Squashman wrote:Now you are confusing me. You just said this.
Yes, i wrote this because of:
Samir wrote:I've got this so far:
Code: Select all
START NOTEPAD BAT00000678.RPT
START /W NOTEPAD BAT00000875.RPT
ECHO DONE EDITING
This will allow the batch continue when the second notepad is closed, but if the user accidentally closes it first, the batch will think the editing is done on both.
Squashman wrote:I am not getting that result at all. If I close the first instance of Notepad my batch file it still waiting for the second instance to close before the batch file continues.
After that i've posted a solution how to wait for both notepads:
penpen wrote:You have no output, so you could use:
Code: Select all
@echo off
NOTEPAD BAT00000678.RPT | NOTEPAD BAT00000875.RPT
ECHO DONE EDITING
penpen
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#14
Post
by Squashman » 30 Oct 2015 13:59
penpen wrote:I don't see the benefit of using "start /W" when using pipes, especially if you want to keep it simple.
The batch already waits all called threads to close before continuing with the next line.
penpen
I can't get mine to work without using START.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#15
Post
by Squashman » 30 Oct 2015 14:02
Penpen,
I must be having a bad day. I am not following any timelines today. I thought you were saying your piped example was continuing when closing the 2nd instance of notepad. I did not realize your comment was in reference to Samir's code.