Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

qx command outputs

by dmouille (Novice)
on Jan 15, 2002 at 04:49 UTC ( [id://138781]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks,

Is there a way to redirect the output of a qx command to a logfile. I could write:

print `$doscommand`;,

after redirecting STDOUT. I'd really like to just be able to write something like:

`$doscommand`

Thanks

Replies are listed 'Best First'.
Re: qx command outputs
by dws (Chancellor) on Jan 15, 2002 at 04:55 UTC
    Is there a way to redirect the output of a qx command to a logfile.

    Would   system("$doscommand > $logfile"); work? It's a little less work than

    open(LOG, ">$logfile") or die "$logfile: $!"; print LOG `$doscommand`; close LOG;
      Using the shell to redirect the output could be very bad. It's rather insecure and you are relying upon the shell to parse more. For example, this appears to be M$, if $logfile contains any spaces this will fail, you would need:
      print system(qq($doscommand > "$logfile"));
      Though I think
      #replace . w/ . if 5.6++ open(LOG, '>>'. $logfile); print LOG qx($doscommand);
      would be better.

      --
      perl -pe "s/\b;([st])/'\1/mg"

Re: qx command outputs
by rbc (Curate) on Jan 15, 2002 at 04:56 UTC
    Why not do ...

    `$doscommand > $logfile`

    --
    Its like a dog that can sing and dance.
    It's remarkable because it can do it.
    Not that it can do it well.
      Don't you mean...

      "Sir, a woman's preaching is like a dog's walking on his hind legs.
      It is not done well; but you are surprised to find it done at all."

      -Samuel Johnson

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://138781]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-28 21:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found