我正在使用以下代码:
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 :(得分: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