Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: System command using array and pipe

by ikegami (Patriarch)
on Jun 06, 2011 at 18:17 UTC ( [id://908340]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^5: System command using array and pipe
by philipbailey (Curate) on Jun 06, 2011 at 20:08 UTC

    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.

      I prefer
      my ($passwd_lit, $path_lit) = map text_to_shell_lit, $passwd, $path; system("mysqldump --add-drop-table -uroot -p$passwd_lit mydatabase | g +zip -9c > $path_lit");
      to
      my $passwd_lit = $passwd; my $path_lit = $path; s#'#'\\''#g for $passwd_lit, $path_lit; system("mysqldump --add-drop-table -uroot -p'$passwd_lit' mydatabase | + gzip -9c > '$path_lit'");

      but to each his own.

      By the way, your quoting was buggy. "\" is not special in sh single-quoted literals.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found