in reply to Getting rid of extra outputs

How are you calling the external program?

If you are calling it like this

my $cmd = 'ls'; my $result = `$cmd`;

..then consider the following approach:

my $cmd = 'ls 2>&1'; my $result = `$cmd`;

The purpose of the 2>&1 is to take anything output to STDERR and redirect to STDOUT.

This will be of no use if your script is on a Win32 machine.

Replies are listed 'Best First'.
Re^2: Getting rid of extra outputs
by sandrider (Acolyte) on May 27, 2005 at 07:57 UTC

    No I don't call it like that.

    It is a.so file that is called by a.pm module that is provided. I call the external.pm and it calls the external.so file.

    When I run it via command line I get things like buffering 10000... and then after the results will be returned. I have a feeling that when I do a use external, it makes those statements. Is there a work around w/o having to edit external.pm? I don't want to mess about with another persons script.

      Seems like you want to temporarily redirect STDOUT to somewhere else?

      You'll find lots of good stuff if you Super Search here for "redirect stdout" or similar.

      This is a VERY basic way of doing it, which might get you started:

      print "This goes to stdout\n"; { local *STDOUT; open STDOUT, '>/tmp/myoutput'; print "This gets redirected\n"; # more code here that prints stuff to stdout } print "Back to normal stdout\n";

      If you really don't need the output of your external.pm then change /tmp/myoutput to /dev/null (if you're on Unix).

      Disclaimer: I've never actually used techniques like this in real code, there may be problems/caveats etc. Searching this site should turn up more robust solutions!


      s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&