您需要一个外壳来实现外壳功能(例如重定向)。所以在你的命令前加上“%comspec% /c”。
你知道 .Exec 允许读取被调用进程的 StdOut/StdErr 吗?
证据:
>> f = "c:\temp\pscp.log"
>> c = "pscp -pw pword -ls user@host:/home"
>> set s = CreateObject("WScript.Shell")
>> WScript.Echo s.Run(c & " > " & f, 0, True)
>> WScript.Echo s.Run( "%comspec% /c " & c & " > " & f, 0, True)
>> WScript.Echo goFS.OpenTextFile(f).ReadAll()
>> WScript.Echo s.Exec(c).Stdout.ReadAll()
>>
1 <-- no shell/%comspec%, no luck
0 <-- it did not fail
Listing directory /home <-- .Run did work with shell
drwxr-xr-x 5 root root 4096 Feb 22 2011 .
...
Listing directory /home <-- .Exec().Stdout.ReadAll() works
drwxr-xr-x 5 root root 4096 Feb 22 2011 .
...