The problem is that
open2 creates new filehandles for you to read from and write to and assigns them to the handles you pass it, instead of just using the ones you pass it. What you really want to do is more like this (which works for me):
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket::INET;
use POSIX;
my $sock = IO::Socket::INET->new(PeerHost => 'example.com',
PeerPort => 9999)
or die "Couldn't open socket: $!\n";
my $pid = fork;
if (!defined($pid)) { die "Couldn't fork: $!\n"; }
if (!$pid) {
# child
POSIX::close(0);
POSIX::close(1);
POSIX::dup2(fileno($sock),0);
POSIX::dup2(fileno($sock),1);
print "Running lsz $0...\n";
exec('lsz','-v',$0)
or die "Couldn't run zmodem: $!\n";
}
# Parent
wait
or die "lsz failed: $?\n";
print "lsz exited $?\n";
Note that example.com isn't a real system, on my system, sz is called lsz, and this script sends a copy of its own source code.
Also, you'll want to make sure you use the appropriate options to sz and rz to make them telnet-safe; otherwise some of the characters they send could be interpreted as telnet escape sequences, which will cause you no end of grief. I use the -e and -b options for zmodem over ssh, and it usually works.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.