http://qs1969.pair.com?node_id=136997

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am running a Perl script on a Win NT machine that retrieves web log files and data from servers outside of a firewall. I use an NT command line version of ssh and scp (called plink and pscp) from within the Perl script. The Perl script is run socksified under sockscap32. For some reason, I cannot capture (save to a variable) string data that results from a backticked or open/piped ssh call within the Perl script whenever it is run socksified. If it is not socksified, everything works fine. Here is an example of what I want to do:

myscript.pl -------- $data = `plink -ssh -pass mypass someuser@external.machine.com "ls -l +/home/someuser"`; # Do something with $data.... --------

In order to socksify the Perl script, I call
sc32.exe c:\Perl\bin\Perl.exe myscript.pl

from within a batch file. The ugly workaround I have involves writing the output of the ssh command on the remote machine to a file and then scp'ing the file to my local machine. Please help me find something elegant! Thank you,
Mark Hoefer
mark_hoefer@agilent.com

Replies are listed 'Best First'.
Re: Capturing data with backticks and sockscap
by kwoff (Friar) on Jan 09, 2002 at 03:13 UTC
    Did you test that "socksification" (whatever that is) is what really is the cause? For example, by capturing output of a hello world script first unsocksified then socksified. Also maybe it is failing as a side-effect of trying to enable socksification (sorry, I like this word), not just the fact that it's socksed. For instance, you used a wrong flag or interpolated some variable on the shell command line. In particular, there is a `@' in your command-line that I have my eye on. Did you use the `-w' flag and `use strict'?
      The script runs fine when not socksified, although it will not connect to the external servers (because it is not socksified...). It will connect to any servers internal to our firewall and I can capture the output from a backticked ssh call.

      When I call the socksified Perl script from the command line, another window pops open. The script does not execute within the window from which I called it.

      Any more ideas?