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

Re: System command using array and pipe

by philipbailey (Chaplain)
on Jun 04, 2011 at 08:57 UTC ( #908116=note: print w/ replies, xml ) Need Help??


in reply to System command using array and pipe

I would use a simpler solution than those presented so far: use system() with a scalar argument and simply quote the path containing a space so that the shell sees it as a single argument.

system("mysqldump --add-drop-table -uroot -ppassword mydatabase | gzip -9c > '/home/username/Ubuntu One/mydatabase.sql.gz'");


Comment on Re: System command using array and pipe
Download Code
Re^2: System command using array and pipe
by ikegami (Pope) on Jun 04, 2011 at 19:14 UTC
    That's basically the second one I posted except you don't handle "'" in paths, spaces and other symbols in passwords, etc.

      Your comments are fair, but in common use cases appropriate quoting of the shell command line is sufficient, especially if one can control the contents of the password and filename. If these come from arbitrary user input, then your approach is more reasonable.

        I'm not sure what you mean. I can guess you'd mean one of these.
        • Store the shell literal in the config.

          my $password = '...'; # Not the password, but a shell literal of the +password. system( ... "-p$password" ... );
        • Pretend the config is a shell literal.

          my $password = '...'; system( ... "-p$password" ... ); # Pretend $password is a shell liter +al.
        • Embed the config data in the command

          system( ... "-p..." ... );

        Every one of these are very unappealing to me.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://908116]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-08-30 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls