Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Accessing an executable from perl script

by abcdefg (Acolyte)
on Mar 01, 2012 at 22:37 UTC ( #957341=perlquestion: print w/replies, xml ) Need Help??

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

Hi There, I have a client server application in which client sends an input file to server ,server uses a tool called abc.exe on that input file, which gives an output file and sends it back to client.The name for the output file is basically output_input file.if the output file with the same name is already present then it increments the suffix at each run. I have written this code but its not working correctly.I guess there is some problem with the $abc_cmd.Can anyone tell me what I am doing wrong?

# Setup some default filenames and command strings. my $input_file; my $output_file = "output.$input_file"; my $rcv_filesize; my $abc_cmd; my $buf; my $error = "ACK\n"; $rcv_filesize = 0; my $i = 1; while (-e $output_file) { $output_file = "output.$input_file$i"; $i++; } $abc_cmd = "abc.exe" -i $input_file -o $output_file"; print $client_socket "ACK\n"; system $abc_cmd; # Run the command print "DONE\n"; # Open the file for reading open(INFILE, $output_file) || die "ERROR: Could not open out +put_file for reading!\n"; binmode INFILE; { local $/; $output_data = <INFILE>; } close(INFILE); print "$prefix Sending $output_file to the client... "; $client_socket->write($output_data, length($output_data)); print length($output_data), " bytes: DONE\n"; $client_socket->close(); print "$prefix Socket closed, operation completed!\n";

Replies are listed 'Best First'.
Re: Accessing an executable from perl script
by onelesd (Pilgrim) on Mar 01, 2012 at 22:50 UTC
    system($abc_cmd) == 0 or die $! ;
Re: Accessing an executable from perl script
by JavaFan (Canon) on Mar 01, 2012 at 22:47 UTC
    $abc_cmd = "abc.exe" -i $input_file -o $output_file";
    This doesn't compile.
    system $abc_cmd;
    You're neither checking the return value of system, nor are you checking $?. If you expect you have a problem with $abc_cmd, checking those values is something you ought to be before asking others to debug your program.
      so if you're looking fo help debugging your code you better make sure to debug it first?
Re: Accessing an executable from perl script
by kcott (Archbishop) on Mar 02, 2012 at 09:30 UTC

    To get the error status from $abc_cmd, you can write:

    system($abc_cmd) and die $? >> 8;

    You can inspect $? in other ways: see system.

    There are other variables you may want to check: see perlvar - Error Variables.

    -- Ken

      or using some module like autodie could be handy, here is a link

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://957341]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2023-03-21 19:42 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.