[Israel.pm] integrating unix commands
lists at woobling.org
Tue Jan 13 07:07:24 PST 2004
On Mon, Jan 12, 2004 at 06:17:15PM +0100, Lena Farid wrote:
> Anyone know how to integrate a unix command in a perl script? like what
> is the syntax for it?
Well, people already mentioned backticks. There's also system and exec
(see perlfunc), but the more flexible way is via pipes, IMHO.
open H, "-|", "uname", "-a"; # returns a PID
print <H>; # reads from uname
close H; # will wait on a child process
open H, "|-", "perl";
print H @codelines; # watch for SIGPIPE
close H; # will wait on a child
if you want something like open H, "|-|", see the core modules
IPC::Open2 and IPC::Open3. They're a bit more heavy to work with, but
practice makes perfect.
the pipe call and the socketpair call are also useful if you're going
to fork and want to communicate.
perldoc perlipc has lots of information on this topic. I learnt most
of how UNIX works without having a POSIX lookalike (macos 9), because
it is so complete... =)
() Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418 perl hacker &
/\ kung foo master: /me supports the ASCII Ribbon Campaign: neeyah!!!
More information about the Perl