5

Let's say we execute a command as below and redirect the console output into text file.

My issue is that there is pause commands within the batch script and when redirecting like this, I cannot know when to hit enter to continue the batch.

Please help me to get the batch "ignores" the pause commands without changing the batch itself. I prefer to get some redirect/pipe syntax.

MyBatchScriptWithPause.bat > SomeFile.txt
Nam G VU
  • 33,193
  • 69
  • 233
  • 372

3 Answers3

3

This should do it:

 (echo.&echo.&echo.&echo.) | MyBatchScriptWithPause.bat > somefile.txt

assuming that no other command is expecting user input in that batch file.

Edit
It also assumes that only a single pause command is in that file. Otherwise Andriy's suggestion should work.

  • 1
    The OP says: *'`pause` **commands**'*. I think, instead of `echo x` it might be `type file.txt` where `file.txt` is a file with umpteen empty lines. – Andriy M Jun 17 '11 at 11:47
  • 1
    Although `(echo.&echo.&echo.&echo.)|MyBatchScriptWithPause.bat > somefile.txt` might work too. – Andriy M Jun 17 '11 at 11:49
  • Chosen as accepted answer.Please update your answer to include `(echo.&echo.&echo.&echo.)`. Thank you. – Nam G VU Jul 06 '11 at 02:49
3
MyBatchScriptWithPause.bat > SomeFile.txt < nul

nul is a DOS device that will provide infinite null data, so it will act as input whenever the script needs some. It is still available even on modern Windows versions.

mrb
  • 3,281
  • 1
  • 20
  • 31
1

I am not sure about ignoring the pauses, but you could redirect them to standard error:

pause 1>&2

which would allow you to know when a pause had occurred.

Paul W
  • 1,039
  • 9
  • 18