Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Need help on perl Expect Module

by sriram83.life (Acolyte)
on Apr 23, 2014 at 06:08 UTC ( [id://1083279]=note: print w/replies, xml ) Need Help??


in reply to Re: Need help on perl Expect Module
in thread Need help on perl Expect Module

Hi Ken,

Here is my execute_command code which just executes a command in shell and returns its exit status.

sub execute_command { my($command) = @_; return &execute_command_rc(0,$command); } #Same, but can specify a return code to check for success sub execute_command_rc { my $expectedrc = $_[0]; my $command = $_[1]; my $pid = &my_fork($command); my $returned_pid = waitpid($pid,0); my $status = $?; &log_and_exit("no child procs to collect?????",$failure) if ($returned_pid == -1); &log_and_exit("returned pid: $returned_pid should have been $pid",$f +ailure) if ($returned_pid != $pid); # tim thinks perl should have macros like WEXITSTATUS my $exit_value = $status >> 8; my $signal_num = $status & 127; my $dumped_core = $status & 128; &log_message("$command exited with status: $exit_value (instead of $ +expectedrc)") if ($exit_value != $expectedrc); &log_message("$command killed by signal: $signal_num") if ($signal_num); &log_message("$command dumped core") if ($dumped_core); # emulate bash behavior. if process is killed, then return (128 | si +gnal no.) return ($signal_num | 128) if ($signal_num); return $exit_value; }

log_message and log_and_exit sub routines are just logging sub routines.They are not for this context.

My main focus here is,to unzip continuously and recursively and replace duplicate files that get unzipped. Thanks for your suggestion Ken, unzip -o helps overwrite files with out prompt.

--Sriram

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1083279]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-16 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found