0

wscript を使用して pscp 経由で 1 つのファイルを転送したいのですが、このコードは機能しません。エラーはスローされませんが、ファイルを転送したり、出力を作成したりしません。

Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Exec "C:\scripts\putty\pscp.exe -pw password C:\file_to_transfer.txt user@server.cz:/directory  2>> C:\Log_file.txt"

手伝ってくれてありがとう....

4

1 に答える 1

0

シェル機能 (リダイレクトなど) にはシェルが必要です。したがって、コマンドの先頭に「%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 .
...
于 2014-04-03T14:53:30.377 に答える