in reply to Question using system.

From the free manual for system:
This is not what you want to use to capture the output from a command, for that you should use merely backticks or qx//, as described in "`STRING`" in perlop.
my @output = `getfilesdata file.txt`;

Update: This is also a FAQ in perlfaq8, Why can't I get the output of a command with system()?

Replies are listed 'Best First'.
Re^2: Question using system.
by pjotrik (Friar) on Jul 10, 2008 at 15:05 UTC

    Or you may use open with pipe, as described in perlipc. That allows you to work with the commands output as with any other (readonly) filehandle.

    open(my $cmd, 'getfilesdata file.txt |')
      Better yet:
      open(my $cmd, '-|', 'getfilesdata', 'file.txt')

        Perhaps I don't understand IPC as well as I thought I did. ikegami, would you mind explaining why this is supposed to be better?

        
        -- 
        Human history becomes more and more a race between education and catastrophe. -- HG Wells
        
Re^2: Question using system.
by rovf (Priest) on Jul 11, 2008 at 09:17 UTC
    Why can't I get the output of a command with system()?
    Because it is not designed that way. system has a different purpose, that is running a program, which even might be interactive. Think about, for instance, system('bash').
    -- 
    Ronald Fischer <ynnor@mm.st>