开发者

Problem with `pause` command when redirecting a command-line log to file

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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜