in reply to which module - linux/process

you can use backticks, or a pipe open
my $output = `ls -la`; # or open PIPE, "ls -la |"; while(<PIPE>) { .... }

Oha

Replies are listed 'Best First'.
Re^2: which module - linux/process
by salva (Canon) on Sep 25, 2007 at 10:55 UTC
    or system if the command output is not going to be used later:
    system($command, @args);

    It is documented in perlfunc

      Yes, system(command,args) is what i use

      What i need is to wait for the above command to complete and control passed back to the perl script, so i can do something more in there

        but that's what system does!

        Maybe the shell script you are calling is forking more processes and not waiting for them.

        system will fork/exec and wait
Re^2: which module - linux/process
by Anonymous Monk on Sep 25, 2007 at 10:55 UTC

    I was trying something on the lines of waitpid, fork and exec. But waitpid dint work for me

      As noted, you will need to use the system(...) or `...` to execute any system-level commands. These commands will wait for the external processes to complete.

      But you mentioned you would like to try using fork and wait/waitpid, so try this example:

      my $pid; if (defined($pid = fork)) { if ($pid) { &parent(); } else { &child(); } } else { die "Fork didn't work...\n"; } sub child { print "Running child process instructions...\n"; sleep 5; # If you have system-level commands to process, # you will still need to use system(...) or `...` exit; } sub parent { waitpid($pid,0); # Will wait for a specific child process # wait; # Will wait for ANY child process to finish print "Finished waiting for child process $pid\n"; }
        exactly what i was looking for, thanks so much!