From: lbo_user on 27 Nov 2007 19:38 Right, I must apologise, it's late and I'm not thinking straight. Ignore my last post as I have found the real reason this time. I'm using a FreeNAS server which doesn't seem to like me reading and writing to it at the same time. If I run the original script and stream from the FreeNAS to my local machine everything is fine. If I stream from AND try to write to the FreeNAS it barfs. Definitely not a Perl problem, but thanks for all the help.
From: John W. Krahn on 27 Nov 2007 21:31 lbo_user wrote: > > OK, so I've got to the bottom of the problem and it's not what I would > have thought. The directory paths were all fine but when I changed > the script to use an intermediate temp file instead of using the pipe > it all started working. > > The original code was: > > my $convert_command = "$flaccmd @flacargs \"$quotedsrc\"" . " | > $lamecmd @lameargs - \"$tmpfilename\""; > system($convert_command); > > which bailed with the error above. However, if I changed it to: > > my $flacoutname = $tmpfilename . "_tmp"; > my $flac_command = "$flaccmd @flacargs \"$quotedsrc\" -o > \"$flacoutname\""; > my $lame_command = "$lamecmd @lameargs \"$flacoutname\" > \"$tmpfilename\""; > system($flac_command); > system($lame_command); > unlink $flacoutname; > > everything was fine. What is it about that concatenation with the > pipe command that is wrong when used within Perl's system? When you use a piped stream perl's system() invokes a shell to (parse and) run the command(s). Without the pipe the command(s) are run without a shell. John -- use Perl; program fulfillment
From: Ben Morrow on 27 Nov 2007 21:53
Quoth "John W. Krahn" <krahnj(a)telus.net>: > lbo_user wrote: > > > > OK, so I've got to the bottom of the problem and it's not what I would > > have thought. The directory paths were all fine but when I changed > > the script to use an intermediate temp file instead of using the pipe > > it all started working. > > > > The original code was: > > > > my $convert_command = "$flaccmd @flacargs \"$quotedsrc\"" . " | > > $lamecmd @lameargs - \"$tmpfilename\""; > > system($convert_command); > > > > which bailed with the error above. However, if I changed it to: > > > > my $flacoutname = $tmpfilename . "_tmp"; > > my $flac_command = "$flaccmd @flacargs \"$quotedsrc\" -o > > \"$flacoutname\""; > > my $lame_command = "$lamecmd @lameargs \"$flacoutname\" > > \"$tmpfilename\""; > > system($flac_command); > > system($lame_command); > > unlink $flacoutname; > > > > everything was fine. What is it about that concatenation with the > > pipe command that is wrong when used within Perl's system? > > When you use a piped stream perl's system() invokes a shell to (parse > and) run the command(s). Without the pipe the command(s) are run > without a shell. " counts as a shell metacharacter (perl doesn't want to try to understand your shell's quoting rules) and will still cause perl to use the shell. Since avoiding the shell is usually a good thing, this example would be better written system @$_ for [$flaccmd, @flacargs, $quotedsrc, -o => $flacoutname], [$lamecmd, @lameargs, $flacoutname, $tmpfilename]; having first made sure that there is no quoting of the parameters: $quotedsrc, for instance, sounds like it's been quoted (:)), and mustn't be. Ben |