non*_*one 40 batch redirection command-line
我想从一个批处理文件中同时运行两个程序,并将第一个程序的输出重定向到一个文本文件中,如:
start python 1st.py arg1 arg2 > out.txt
start 2nd.exe %1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)
当程序按预期运行时,所有输出都显示在标准输出上。
Pat*_*our 42
您可能需要这样做:
start cmd /c python 1st.py arg1 arg2 ^> out.txt
Run Code Online (Sandbox Code Playgroud)
重定向适用于start
命令,但不知何故不适用于cmd.exe
它运行的实例。
如果>
操作符被转义,一切都应该正常工作:
start 1st.py arg1 arg2 ^> out.txt
Run Code Online (Sandbox Code Playgroud)
(如果您还想重定向 stderr,请使用2^>
它。)
此外,如果你想重定向 stderr 和 stdout 这对我有用
开始调用 delay.bat ^1^> log.txt ^2^>^&^1
似乎每个字符基本上都需要转义。该命令通常如下所示:
延迟.bat 1> log.txt 2>&1
对我来说,诀窍是将命令移动到一个单独的批处理文件中:
rem this first batch file triggers the second one:
start the_second.bat arg1 arg2 out.txt
Run Code Online (Sandbox Code Playgroud)
the_second.bat 然后看起来像这样:
python 1st.py %1 %2 > %3
Run Code Online (Sandbox Code Playgroud)