j0e has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm writing an application which pipes data from mkisofs to cdrecord under Unix. Unfortunatley, I have to do this without the shell interpreting weird characters in the filenames which I'm passing to the script, so I have to use safe pipe opens. So far, I've written the following code to do this:

use POSIX qw(sys_wait_h); use strict; ... if ($cdrpid = open(CDREC, "|-")) { if ($isopid = open(MKISO, "-|")) { my ($rin, $nfd) = ("",""); vec($rin, fileno(CDREC), 1) = 1; if (not($nfd = select($rin, $rin, undef, 20))) { die "argh timeout"; } while (<MKISO>) { print CDREC; } close(MKISO); } else { exec "$OPT{isobin}", '-r', @ARGV; } close(CDREC); } else { exec "$OPT{cdbin}", "speed=$OPT{speed}", dev=$OPT{dev}", "tsize=@t +size", '-waiti', '-data', '-'; } waitpid($isopid, &WNOHANG); waitpid($cdrpid, &WNOHANG);
Okay, it sucks but it more or less works. I have two problems with this current implemenation, however:

1) I would like to be able to optionally pipe the data from mkisofs to aespipe and then to cdrecord to facilitate creating encrypted CD-Rs. Right now I can't really think of a good way to do this.

2) This program is going to eventually have a frontend, so I'm going to need to read status information printed from mkisofs to STDERR to update a progress bar thingy. I'm not really sure of what the best way to do this would be either.

Any ideas would be appriciated.

Replies are listed 'Best First'.
Re: Mysteries of IPC...
by steves (Curate) on Feb 09, 2003 at 06:32 UTC

    Two thoughts:

    1. IPC::Run will let you do shell-like piping without invoking the shell.
    2. You could just quote the file names so the shell doesn't interpret special characters in them.