Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pipe putty pscp output to text file

1,913 views
Skip to first unread message

req...@gmail.com

unread,
Mar 31, 2008, 11:50:30 AM3/31/08
to
I'm looking at a way to pipe the output of the putty application pscp
to a text file. The application writes out data to a command window,
so I was hoping I could use something like:

return = WSHShell.run (puttydir & "pscp.exe -batch -r " & localdir & "
" & puttysess & ":" & remotedir & " > C:\output.log",2,true)

Where return will check for a bool if the shell command ran
successfully, the pipe > works for the ping command, but when I run it
for pscp I receive an error.

This is what I'm running for ping:

return = WSHShell.run ("cmd /c ping nasctxtest >" & outputfile,2,true)

This is what i'm trying for pscp:

localdir = "C:\fromdir"
puttysess="sessionid"
remotedir="/remote/dir"

return = WSHShell.run ("C:\scripts" & "pscp.exe -batch -r " & localdir
& " " & puttysess & ":" & remotedir & " > C:\output.log",2,true)

ekkehard.horner

unread,
Mar 31, 2008, 12:09:08 PM3/31/08
to
req...@gmail.com schrieb:

(1) you should WScript.Echo or MsgBox the command to .Run

localdir = "C:\fromdir"
puttysess="sessionid"
remotedir="/remote/dir"

sCmd = "C:\scripts" & "pscp.exe -batch -r " & localdir _


& " " & puttysess & ":" & remotedir & " > C:\output.log"

return = WSHShell.run( sCmd, 2, true )

then you'll see mistakes like

"C:\scripts" & "pscp.exe ..." ==> "C:\scriptspscp.exe"

(missing "\")

(2) You need a shell ("cmd /c" or better "%comspec% /c") like in your

return = WSHShell.run ("cmd /c ping nasctxtest >" & outputfile,2,true)

line to get device rerouting. So prepend this to sCmd

Pegasus (MVP)

unread,
Mar 31, 2008, 12:13:54 PM3/31/08
to

<req...@gmail.com> wrote in message
news:6f1d6cc1-b548-45f3...@f63g2000hsf.googlegroups.com...

Redirections are handled by the Command Processor. Pspc.exe
knows nothing about such things. Try this instead:
Set exec1Obj = wshShell.Exec("cmd.exe /c c:\scripts\pscp.exe .... >
c:\process1.txt")

You're probably short of a backslash too. Instead of writing
"C:\scripts" & "pscp.exe" you may want to write
"C:\scripts\pscp.exe "
There is no need to break up the string in the middle.


Richard Mueller [MVP]

unread,
Mar 31, 2008, 12:22:32 PM3/31/08
to

<req...@gmail.com> wrote in message
news:6f1d6cc1-b548-45f3...@f63g2000hsf.googlegroups.com...

I would use %comspec% /c to run the *.exe. The command processor provides
the redirection capability. You also may be missing a trailing backslash in
your path to the executable. Perhaps:

return = WSHShell.Run("%comspec% /c c:\scripts\pscp.exe - batch -r " _
& localdir & " " & puttysess & ":" & remotedir & " > c:\output.log", 2,
True)

You also might want to echo the command to the command prompt to make sure
it is what you intend:

localdir = "C:\fromdir"
puttysess="sessionid"
remotedir="/remote/dir"

cmd = "%comspec% /c c:\scripts\pscp.exe - batch -r " _
& localdir & " " & puttysess & ":" & remotedir & " > c:\output.log"

Wscript.Echo cmd
return = WSHShell.run(cmd)

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


req...@gmail.com

unread,
Mar 31, 2008, 3:11:36 PM3/31/08
to
I had tried the cmd.exe before, but I noticed I've been typing -c the
last few times. I dont know if it was my syntax error or the %comspec%
but I've got it working!


On Mar 31, 11:22 am, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> <requ...@gmail.com> wrote in message

> --- Hide quoted text -
>
> - Show quoted text -

0 new messages