in reply to Unix command line

For completeness there is also the pipe open:

open PIPE, "|$prog" or die $!

which lets you fire up the external program and then pass a stream of data to it by printing to the pipe.....

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Unix command line
by thens (Scribe) on Sep 30, 2003 at 14:04 UTC

    You should also check for the exit status of the command when using pipe to invoke external commands.

    open will fail

    • if it was not able to fork a process
    • the command was not found.
    If there was any error in execting the command, it can be checked by closing the pipe and checking for the return value.

    The sequence will be

    # opne the pipe, check if fork passed open PIPE, "|$prog" or die $!; # do something with the command like print PIPE @files; # check if the command completed successfully close PIPE or die "Command failed : $! || $?";

    Hope this helps

    -T