Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: System command using array and pipe

by ikegami (Pope)
on Jun 04, 2011 at 19:14 UTC ( #908140=note: print w/replies, xml ) Need Help??

in reply to Re: System command using array and pipe
in thread System command using array and pipe

That's basically the second one I posted except you don't handle "'" in paths, spaces and other symbols in passwords, etc.

Replies are listed 'Best First'.
Re^3: System command using array and pipe
by philipbailey (Chaplain) on Jun 05, 2011 at 09:12 UTC

    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.

        The only issue that cannot be resolved by single quoting relevant parts of the command line is of escaping single quotes. Either do this manually, or do something simple like this:

        s#'#'\\''#g for ($password, $path); system("mysqldump --add-drop-table -uroot -p'$password' mydatabase | g +zip -9c > '$path'");

        Update: s/// command corrected as per ikegami.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://908140]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2018-07-17 07:57 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (357 votes). Check out past polls.