2014-02-10 35 views
0

我使用下面的代碼:如何使用運行命令將標準/錯誤輸出重定向到文件?

cmd = """" & "C:/node/executable/path/node.exe" & """" & " " & """" & "C:/path/to/script.js" & """" & " > " & """" & "C:/path/to/output.txt" & """" 
WshShell.Run cmd, 0, False 

CMD看起來是這樣的:

"C:/node/executable/path/node.exe" "C:/path/to/script.js" > "C:/path/to/output.txt" 

這個腳本作品(它開始在後臺),但是輸出永遠不會重定向到一個文件(文件未出現) 。我做錯了什麼?

回答

0

重定向操作符(「>」)是一個cmd.exe shell特徵。 node.exe過程需要啓動一個cmd.exe進程:

Set WshShell = WScript.CreateObject("WScript.Shell") 

cmd = "cmd.exe /c ""C:\node\executable\path\node.exe"" ""C:\path\to\script.js"" > ""C:\path\to\output.txt""" 

WshShell.Run cmd, 0, False 
相關問題