2013-05-09 376 views
2

我有一個批處理文件,它將使用DOS啓動命令運行多個程序。但是,我無法將程序的結果寫入各自的文本文件。使用DOS啓動命令無法寫入批處理文件處理結果

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

如果我的批處理文件只是

program1.exe > result1.txt 

那麼結果可以被寫入result1.txt

有沒有在我的語法有問題?謝謝。

+0

是的,如果您輸入「start winword.exe> result.log」,則日誌中沒有寫入任何內容。這很平常。 – Endoro 2013-05-09 09:44:57

+0

program1.exe是一個將結果打印到控制檯上的程序,我正在使用重定向操作符將結果寫入文件 – Michael 2013-05-09 09:49:26

+0

某些程序不會將其輸出寫入STDOUT,它們將寫入STDERR或其他Streams(例如java.exe)。 – Endoro 2013-05-09 10:55:08

回答

3

只要程序寫到標準輸出,你可以通過使用單獨的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 
+2

開始「」CMD/C「program1.exe> result1.txt」<---也應該工作。 – foxidrive 2013-05-09 13:19:09

+0

很好的答案,這是我需要的。 =) – Michael 2013-05-09 13:26:44