aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2013-01-22 20:29:01 +0100
committerGravatar Anton Lundin <glance@acc.umu.se>2013-04-09 22:31:12 +0200
commitfb39fe2c7ed9fd09f3a6b5eaa7484aa743b82f16 (patch)
treec2e755f87919cb4709a5072a1b4ee0dd81c44720 /scripts
parent1b9915fcaf6205f718433b904618e1e5a4602c66 (diff)
Simplify pipe management
We don't need to write perl like C.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/mosh14
1 files changed, 4 insertions, 10 deletions
diff --git a/scripts/mosh b/scripts/mosh
index c9e6c29..421dbb1 100755
--- a/scripts/mosh
+++ b/scripts/mosh
@@ -217,15 +217,10 @@ if ( (not defined $colors)
$colors = 0;
}
-my ($p_read, $p_write);
-pipe($p_read, $p_write);
-my $pid = fork;
+my $pid = open(my $pipe, "-|");
die "$0: fork: $!\n" unless ( defined $pid );
if ( $pid == 0 ) { # child
- open STDOUT, ">&", $p_write or die;
- open STDERR, ">&", $p_write or die;
- close $p_write;
- close $p_read;
+ open(STDERR, ">&STDOUT") or die;
my @server = ( 'new', '-s' );
@@ -249,8 +244,7 @@ if ( $pid == 0 ) { # child
} else { # parent
my ( $ip, $port, $key );
my $bad_udp_port_warning = 0;
- close $p_write;
- LINE: while ( <$p_read> ) {
+ LINE: while ( <$pipe> ) {
chomp;
if ( m{^MOSH IP } ) {
if ( defined $ip ) {
@@ -271,7 +265,7 @@ if ( $pid == 0 ) { # child
}
}
waitpid $pid, 0;
- close $p_read;
+ close $pipe;
if ( not defined $ip ) {
die "$0: Did not find remote IP address (is SSH ProxyCommand disabled?).\n";