【问题标题】:Cannot write result of batch file processing using DOS START command无法使用 DOS START 命令写入批处理文件的结果
【发布时间】:2013-05-03 17:59:06
【问题描述】:

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

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

如果我的批处理文件很简单

program1.exe > result1.txt

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

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

【问题讨论】:

  • 是的,如果您键入“start winword.exe > result.log”,则日志中不会写入任何内容。这很正常。
  • program1.exe 是将结果打印到控制台的程序,我正在使用重定向运算符将结果写入文件
  • 有些程序不会将其输出写入 STDOUT,而是写入 STDERR 或其他 Streams(例如 java.exe)。

标签: batch-file batch-processing dos


【解决方案1】:

只要程序写入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

【讨论】:

  • start "" CMD /C "program1.exe>result1.txt"
  • 很好的答案,这就是我需要的。 =)
猜你喜欢
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-12
  • 2012-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多