Pausing Batch File Execution for External Program

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Pausing Batch File Execution for External Program

#1 Post by Samir » 09 Sep 2013 14:49

This has been covered in previous threads, but I never saw what I just accidentally did.

I opened a file in notepad using the command-line like so:
notepad filename.bat

but I accidentally had |more after it (because I originally used type vs notepad):
notepad filename.bat|more

The result was that the command prompt waited until I closed notepad before continuing. I definitely didn't expect that.

I ran this under the XP command prompt. Hope someone finds this useful. 8)

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

Re: Pausing Batch File Execution for External Program

#2 Post by aGerman » 09 Sep 2013 15:36

It's the normal behaviour that cmd.exe executes the command lines of a batch file synchronously. It will also work without the pipe to MORE.
If you want it to work asynchronously you have to use the START command.

Regards
aGerman

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Pausing Batch File Execution for External Program

#3 Post by penpen » 09 Sep 2013 16:37

@aGerman
This is true for batch scripts, but i think he meant from the dos shell, where it is not the normal behavior.

@Samir
You may use this in some cases, for example if you want to create some sample data text files:
You just need a multiline input field, as example this html edit field, and create some sample files using notepad:

Code: Select all

notepad sample1.txt |more
notepad sample2.txt |more
notepad sample3.txt |more
notepad sample4.txt |more
...
notepad sampleN.txt |more
Then just mark all, copy it to the clipboard (ctrl+c) and paste it to a dos shell window (right click, insert).
The result is it opens one notepad after the other: I don't like it if there are 10 or 20 files open at the same time.
So i often do it this way, if the sample text could not be automated.

penpen

Edit: Sorry forgotten: But you could have expected it, think of the behavior of more and the pipe operator.
Last edited by penpen on 09 Sep 2013 17:45, edited 1 time in total.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Pausing Batch File Execution for External Program

#4 Post by Samir » 09 Sep 2013 16:42

aGerman wrote:It's the normal behaviour that cmd.exe executes the command lines of a batch file synchronously. It will also work without the pipe to MORE.
If you want it to work asynchronously you have to use the START command.

Regards
aGerman
I forgot about that. You're absolutely right that it's normal behavior in batch. I just didn't expect that behavior from the command prompt.
penpen wrote:@aGerman
This is true for batch scripts, but i think he meant from the dos shell, where it is not the normal behavior.

@Samir
You may use this in some cases, for example if you want to create some sample data text files:
You just need a multiline input field, as example this html edit field, and create some sample files using notepad:

Code: Select all

notepad sample1.txt |more
notepad sample2.txt |more
notepad sample3.txt |more
notepad sample4.txt |more
...
notepad sampleN.txt |more
Then just mark all, copy it to the clipboard (ctrl+c) and paste it to a dos shell window (right click, insert).
The result is it opens one notepad after the other: I don't like it if there are 10 or 20 files open at the same time.
So i often do it this way, if the sample text could not be automated.

penpen
Exactly. I accidentally did this in a command prompt.

Very interesting use penpen. I usually just let a bunch of notepads open up, but you're right that this trick does have some use when you have to edit a bunch of files in sequence. :)

Post Reply