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

Hey guys, I hope this finds you well. I'm using perl (well trying) to telnet to a remote server, run the command which will pipe its output to a file, wait until complete, then FTP it back to me. The command I want is... /apps/current/bin/getz -vf "off des" "[$database -type: primary|predicted]" &> /data/holdFile.txt so in perl after it has logged into the server (which I'm certain is working) I use:
$tel->print("/apps/current/bin/getz -vf \"off des\" \"[$database -type +: primary|predicted]\" &> /data/holdFile.txt"); $tel->waitfor('/$/');
The differences obviously by putting '\' in so the command line is passed the double quote marks properly. Unfortunately an error occurs when running this from perl (runs fine on the commandline when I put it the first code snippet in). SO I've got a feeling the backslashes are wrong, but what other special characters do I need to switch off here? Thanks again guys!

Replies are listed 'Best First'.
Re: Telnet print issues...
by Gangabass (Vicar) on Oct 03, 2007 at 10:15 UTC

    Did you try

    tel->print('/apps/current/bin/getz -vf "off des" "[$database -type: pr +imary|predicted]" &> /data/holdFile.txt');
      Hey Gangabass, thanks for the reply. Yeah I tried that, but that falls down as well. Think that's because $database is called inside that string which if in single quotes, will only return '$database' and not the variables contents. Is there a way I can get the output of whatever the commandline is saying to my telnet statement back onto my local commandline so I can see if it's saying giving NULL command, or broken pipe etc? Thanks

        In that case, how about breaking it up into concatenated substrings?

        tel->print('/apps/current/bin/getz -vf "off des" "[' . $database . ' -type: primary|predicted]" &> /data/holdFile.txt');

        As for capturing the output of your command, try the backticks: http://perldoc.perl.org/perlop.html#%60STRING%60