无法使用DOS START命令写入批处理文件处理的结果

时间:2013-05-09 09:38:31

标签: batch-file batch-processing dos

我有一个批处理文件,它将使用DOS启动命令运行多个程序。但是,我无法将程序的结果写入各自的文本文件。

start program1.exe > result1.txt
start program2.exe > result2.txt

如果我的批处理文件只是

program1.exe > result1.txt

然后可以将结果写入result1.txt

我的语法有问题吗?谢谢。

1 个答案:

答案 0 :(得分:3)

只要程序写入stdout,您就可以通过使用单独的CMD并转义重定向运算符来获取Start调用的命令的输出

试试这个:

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