我有一个批处理文件,它将使用DOS启动命令运行多个程序。但是,我无法将程序的结果写入各自的文本文件。使用DOS启动命令无法写入批处理文件处理结果
start program1.exe > result1.txt
start program2.exe > result2.txt
如果我的批处理文件只是
program1.exe > result1.txt
那么结果可以被写入result1.txt
有没有在我的语法有问题?谢谢。
我有一个批处理文件,它将使用DOS启动命令运行多个程序。但是,我无法将程序的结果写入各自的文本文件。使用DOS启动命令无法写入批处理文件处理结果
start program1.exe > result1.txt
start program2.exe > result2.txt
如果我的批处理文件只是
program1.exe > result1.txt
那么结果可以被写入result1.txt
有没有在我的语法有问题?谢谢。
只要程序写到标准输出,你可以通过使用单独的CMD和逃避重定向运营商处获得由开始称为命令的输出
试试这个:
start "" CMD /C program1.exe^>result1.txt
start "" CMD /C program2.exe^>result2.txt
例如:
c:\Scripts\Batch>start "" CMD /C ping -n 1 localhost>testping1.txt
c:\Scripts\Batch>type testping1.txt
*Nothing comes up because the file is empty*
c:\Scripts\Batch>start "" CMD /C ping -n 1 localhost^>testping1.txt
c:\Scripts\Batch>type testping1.txt
Pinging YourComputer [::1] with 32 bytes of data:
Reply from ::1: time<1ms
Ping statistics for ::1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
是的,如果您输入“start winword.exe> result.log”,则日志中没有写入任何内容。这很平常。 – Endoro 2013-05-09 09:44:57
program1.exe是一个将结果打印到控制台上的程序,我正在使用重定向操作符将结果写入文件 – Michael 2013-05-09 09:49:26
某些程序不会将其输出写入STDOUT,它们将写入STDERR或其他Streams(例如java.exe)。 – Endoro 2013-05-09 10:55:08