Page 1 of 1

Pausing Batch File Execution for External Program

Posted: 09 Sep 2013 14:49
by Samir
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)

Re: Pausing Batch File Execution for External Program

Posted: 09 Sep 2013 15:36
by aGerman
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

Re: Pausing Batch File Execution for External Program

Posted: 09 Sep 2013 16:37
by penpen
@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.

Re: Pausing Batch File Execution for External Program

Posted: 09 Sep 2013 16:42
by Samir
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. :)