V
vikrant
hi
I am trying to store the return value of system command after execution in a forking server.
The command executes successfully but returns "-1". In case of failure, it returns the same value
"-1", like when i am replacing "date" with "data" in system command. From my understanding, it
should return -1 only in case of failure. How do go about distinguishing between a success and
failure call while using the system commnad?
Code:-
-----------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use IO::Socket;
use IO::Select;
$SIG{CHLD} = 'IGNORE';
my $sock = new IO::Socket::INET(
LocalHost => '10.0.0.23',
LocalPort => '36545',
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
REQUEST:
while (my $sNew_Socket = $sock->accept())
{
my $kid=fork();
if ($kid)
{
close $sNew_Socket;
next REQUEST;
}
close $sock;
my $obSelected_Socket = IO::Select->new($sNew_Socket);
my $sData_Recevied;
while( $obSelected_Socket->can_read(20))
{
my $sBuffer;
sysread($sNew_Socket,$sBuffer,1<<10);
$sData_Recevied.=$sBuffer;
if($sBuffer =~/\/END>/)
{
last;
}
}
my $sDatecmd=system("date");
$sNew_Socket->send($sDatecmd);
exit;
}
-----------------------------------------------------------------------------------------------------
Thanks
Vikrant
I am trying to store the return value of system command after execution in a forking server.
The command executes successfully but returns "-1". In case of failure, it returns the same value
"-1", like when i am replacing "date" with "data" in system command. From my understanding, it
should return -1 only in case of failure. How do go about distinguishing between a success and
failure call while using the system commnad?
Code:-
-----------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use IO::Socket;
use IO::Select;
$SIG{CHLD} = 'IGNORE';
my $sock = new IO::Socket::INET(
LocalHost => '10.0.0.23',
LocalPort => '36545',
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
REQUEST:
while (my $sNew_Socket = $sock->accept())
{
my $kid=fork();
if ($kid)
{
close $sNew_Socket;
next REQUEST;
}
close $sock;
my $obSelected_Socket = IO::Select->new($sNew_Socket);
my $sData_Recevied;
while( $obSelected_Socket->can_read(20))
{
my $sBuffer;
sysread($sNew_Socket,$sBuffer,1<<10);
$sData_Recevied.=$sBuffer;
if($sBuffer =~/\/END>/)
{
last;
}
}
my $sDatecmd=system("date");
$sNew_Socket->send($sDatecmd);
exit;
}
-----------------------------------------------------------------------------------------------------
Thanks
Vikrant