2

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

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

如果我的批处理文件只是

program1.exe > result1.txt

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

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

4

1 回答 1

3

只要程序写入标准输出,您就可以通过使用单独的 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
于 2013-05-09T10:44:17.020 回答