2014-04-03 189 views
0

我想通过使用wscript的pscp传输一个文件,此代码不起作用。 它不会抛出任何错误,但它不会传输文件或输出。pscp文件传输错误输出重定向到文件

Dim objShell 
Set objShell = WScript.CreateObject("WScript.Shell") 
objShell.Exec "C:\scripts\putty\pscp.exe -pw password C:\file_to_transfer.txt [email protected]:/directory 2>> C:\Log_file.txt" 

感谢帮助....

回答

0

你需要一个壳特征外壳(例如重定向)。所以在你的命令前加上“%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 . 
... 
+0

感谢,但它并没有为我工作。在第6行上抛出错误char 1 - 所需的goFS对象。 – user3493540

+0

@ user3493540 - 它是*证据*不是'准备好复制和粘贴代码'。请问自己什么对象有一个.OpenTextFile方法。你试过'%comspec%/ c'加法吗? –

+0

这是我在脚本编写中的第一个任务,所以我完全不知道我在做什么。我会很高兴,如果我可以通过pscp传输该文件开始... – user3493540