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

Thanks for your answers. I donīt really think the $command's format is the key, but I will change it to see it goes better. Anyway, how can I check the return value of open an close in an easy way?, because I really think the problem is there, in fact I use the "truss" linux command and I got some Err#9 EBADF (/* Bad file descriptor */)

Replies are listed 'Best First'.
Re: segmentation fault
by moritz (Cardinal) on Sep 22, 2009 at 12:37 UTC
    Is your Perl script segfaulting, or the program it starts? If it's the external program, we probably can't help you at all.

    Also this looks very suspicious to me:

    $command= "cfi -N $bsc -1 \"RLSTP:CELL=$cell;\" |" or warn "Cant acces +s to BSC $bsc\n"; open CFI, $command;

    The string $command will never be false, so the warn is never executed. Likely you want to check the return value of open, though. And you should also check the return value from close, because that's where you can learn about the exit status of the external program (if I remember correctly).

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: segmentation fault
by Bloodnok (Vicar) on Sep 22, 2009 at 13:14 UTC
    I agree with moritz, however, going a little further, I suspect that:
    $command= "cfi -N $bsc -1 \"RLSTP:CELL=$cell;\" |" or warn "Cant acces +s to BSC $bsc\n"; open CFI, $command;
    should have been written as
    $command= "cfi -N $bsc -1 \"RLSTP:CELL=$cell;\" |"; open CFI, $command or die "Cant access to BSC $bsc\n";
    A user level that continues to overstate my experience :-))
      Actually, I think it should be written as
      my @command = ( 'cfi', '-N', $bsc, '-l', "RLSTP:CELL=$cell;" ); open( CFI "-|", @command ) or die "unable to run \"@command\": $!";
      Using an array to store the individual command-line tokens means that you don't need to worry about quoting or escaping shell-magic characters (like ";").

        Thanks for your answers. I donīt really think the $command's format is the key, but I will change it to see it goes better. Anyway, how can I check the return value of open an close in an easy way?, because I really think the problem is there, in fact I use the "truss" linux command and I got some Err#9 EBADF (/* Bad file descriptor */)