From: Tad McClellan on 13 Nov 2009 16:03 Thomas Barth <txbarth(a)web.de> wrote: > open(SOXIN, "sox $path -r 8000 -c 1 $src_dir/$basename.vox stat |"); You should always, yes *always*, check the return value from open: open(SOXIN, "sox $path -r 8000 -c 1 $src_dir/$basename.vox stat |") die "could not open the sox program: $!"; see also: perldoc -q pipe Why doesn't open() return an error when a pipe open fails? > close(SOXIN); So with "pipe open"s you should also check the return value from close(): close(SOXIN) or die "problem running sox: $!"; -- Tad McClellan email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
From: Ben Morrow on 13 Nov 2009 18:09 Quoth "Uri Guttman" <uri(a)StemSystems.com>: > >> its cleared, I got it with the command > >> open(SOXIN, "sox $path -r 8000 -c 1 $src_dir/$basename.vox stat 2>&1 |"); > > sr> Or this: > > sr> my @soxin = split /\n/, qx/ sox $path -r 8000 -c 1 $src_dir/ > sr> $basename.vox stat /; > > no need for the split. backticks/qx will split on \n in a list context. > > also that won't work as you are using / for the delimiter and / is on > the data. so use another delimiter and {} is usually the best choice > there. Also, that won't work since qx// doesn't automatically do the 2>&1 that was missing in the first place... Ben
From: Uri Guttman on 13 Nov 2009 19:01 >>>>> "BM" == Ben Morrow <ben(a)morrow.me.uk> writes: BM> Quoth "Uri Guttman" <uri(a)StemSystems.com>: >> >> its cleared, I got it with the command >> >> open(SOXIN, "sox $path -r 8000 -c 1 $src_dir/$basename.vox stat 2>&1 |"); >> sr> Or this: >> sr> my @soxin = split /\n/, qx/ sox $path -r 8000 -c 1 $src_dir/ sr> $basename.vox stat /; >> >> no need for the split. backticks/qx will split on \n in a list context. >> >> also that won't work as you are using / for the delimiter and / is on >> the data. so use another delimiter and {} is usually the best choice >> there. BM> Also, that won't work since qx// doesn't automatically do the 2>&1 that BM> was missing in the first place... yeah, i thought about that after i saw the other posts. it wasn't clear from the OP that it was stderr coming out of sox (which is kind of odd anyhow). so the above code is wrong on 3 counts: no need for split, broken delimiter and not redirecing stderr. not bad! :) uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Ben Morrow on 13 Nov 2009 20:12 Quoth "Uri Guttman" <uri(a)StemSystems.com>: > > yeah, i thought about that after i saw the other posts. it wasn't clear > from the OP that it was stderr coming out of sox (which is kind of odd > anyhow). IIRC sox usually expects to emit a (converted) sound file on STDOUT; the 'stat' filter presumably doesn't emit a sound file at all and instead emits some analysis on STDERR. Ben
From: C.DeRykus on 14 Nov 2009 01:04 On Nov 13, 6:00 am, Thomas Barth <txba...(a)web.de> wrote: > Hi, > any Idea how to get the output of this command into an array? The output > is still printed to the screen. The array @soxin keeps empty. > > open(SOXIN, "sox $path -r 8000 -c 1 $src_dir/$basename.vox stat |"); > my @soxin = <SOXIN>; > close(SOXIN); > IPC::Run is another possibility: use IPC::Run qw( run ); use strict ; use warnings; # ***** untested ***** run ["sox $path -r 8000 -c 1 $src_dir/$basename.vox stat"], '<', \my @soxin, \my $err or die "Markdown.pl failed: $?"; -- Charles DeRykus
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: how to install WWW::Mechanize using yum Next: Please help with processing flat file |