【问题标题】:How to redirect standard/error output to file whil using Run command?如何在使用运行命令时将标准/错误输出重定向到文件?
【发布时间】:2014-02-10 16:44:01
【问题描述】:

我正在使用以下代码:

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"

此脚本有效(它在后台启动),但输出永远不会重定向到文件(文件不出现)。我做错了什么?

【问题讨论】:

    标签: vba wsh


    【解决方案1】:

    重定向运算符 (">") 是 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多