in reply to problem with system(), stdin, and stdout

Does your code contain close STDIN;? If yes, does it also contain: open STDIN, "<", "/dev/null";?

Replies are listed 'Best First'.
Re^2: problem with system(), stdin, and stdout
by romero619 (Novice) on Sep 30, 2008 at 01:41 UTC
    Nevermind...stupid yet subtle mistake...
    I wasnt chomping the result from STDIN...
    should have done this:
    chomp($filename=<STDIN>);

    this removes the newline character which kept getting inserted into $filename, giving $filename a value such as '/path/file\n', and thus passing the newline into my $cmd string, making $cmd look like this:

    $cmd = "mycmd -args $filename >outfile"
    ...gives...
    "mycmd -args /path/file\n >outfile"

    So, everytime I passed $cmd to system(), it would execute the cmd and stop at the newline character embedded within $filename, thus skipping the ">outfile" redirection...

    problem solved, but thanks to everyone for pointing out that this apparently should have worked.
    Please add this to your vast collection of mental "gotchas" that can stump users...