Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

system() and output redirect

by llancet (Friar)
on Mar 14, 2014 at 07:32 UTC ( [id://1078298]=perlquestion: print w/replies, xml ) Need Help??

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

Perl's system() function has two modes: if you give one argument, it will have this string parsed by a "shell"; if you give an array, it will use the first one as program name, and directly pass the following things to the program without the process by a "shell"

We know that the second mode is more safe, as it avoids the arguments with spaces being splitted into multiple arguments. So we should prefer the second mode. However, I don't know how to use ">file" in the second mode. If you provide it, it will be transferred into the program, not performing an output redirection. For example:

# This works system("cat foo >bar"); # ">bar" being passed to cat as an argument # and there's no file named ">bar" system('cat', 'foo', '>bar');

Thanks!

Replies are listed 'Best First'.
Re: system() and output redirect (IPC::Run3, Capture::Tiny, shellquote)
by Anonymous Monk on Mar 14, 2014 at 07:44 UTC
Re: system() and output redirect
by vinoth.ree (Monsignor) on Mar 14, 2014 at 10:19 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-18 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found