你需要一个壳特征外壳(例如重定向)。所以在你的命令前加上“%comspec%/ c”。
您是否知道.Exec允许读取被调用进程的StdOut/StdErr?
证据:
>> f = "c:\temp\pscp.log"
>> c = "pscp -pw pword -ls [email protected]:/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 .
...
感谢,但它并没有为我工作。在第6行上抛出错误char 1 - 所需的goFS对象。 – user3493540
@ user3493540 - 它是*证据*不是'准备好复制和粘贴代码'。请问自己什么对象有一个.OpenTextFile方法。你试过'%comspec%/ c'加法吗? –
这是我在脚本编写中的第一个任务,所以我完全不知道我在做什么。我会很高兴,如果我可以通过pscp传输该文件开始... – user3493540