On Fri, 13 Jul 2001, Eric Chun wrote:
> What does
> $pid = open(CMD, "-|")
> mean? I assume this is forking a process, but I have not seen "-|" before.
> Has anybody come across this kind of perl command before?
| is the Unix (and DOS) pipe symbol, where you can take the output of one
command and make it the input into another program. You can "open" a
piped command (either piping into or piping out of), which Perl will fork,
returning the pid.
If you have open(CMD, "| <command>"), anything you print to the filehandle
will be processed by the command. This is useful for sending email to
an MTA like sendmail.
If you have open(CMD, "<command> |"), you can read from the filehandle and
get the output of the command. This is useful for reading the output of,
say, the Unix who command to get a list of people logged into the system.
Now for your example, the perldoc on open also says:
If MODE is "'|-'", the filename is interpreted as
a command to which output is to be piped, and if
MODE is "'-|'", the filename is interpreted as a
command which pipes output to us. In the
2-arguments (and 1-argument) form one should
replace dash ("'-'") with the command. See the
Using open() for IPC entry in the perlipc manpage
for more examples of this. (You are not allowed
to "open" to a command that pipes both in and out,
but see the IPC::Open2 manpage, the IPC::Open3
manpage, and the Bidirectional Communication entry
in the perlipc manpage for alternatives.)
-- Brett
http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Two cars in every pot and a chicken in every garage.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]