in reply to Need help on perl Expect Module

G'day sriram83.life,

Without knowing anything about execute_command(), or the module where it is defined, any answer will involve a lot of guesswork; however, my gut feeling is that Expect is unnecessary.

If the module is a core or CPAN module, provide a link; otherwise, provide the code.

Why are you circumventing execute_command()'s prototypes? Perhaps it's expecting an argument to do what you want. If you don't understand any of that, see perlsub.

I'd probably just use appropriate options for unzip and gunzip such that those commands do what you want. (Options often vary between OSes: see the manpages on your OS to find the correct ones for you.)

-- Ken

Replies are listed 'Best First'.
Re^2: Need help on perl Expect Module
by sriram83.life (Acolyte) on Apr 23, 2014 at 06:08 UTC
    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