in reply to Re^7: Poll: Is your $^X an absolute path? (system @list)
in thread Poll: Is your $^X an absolute path?
I go back to perlport:
Interprocess Communication (IPC) In general, don't directly access the system in code meant to be portable. That means, no "system", "exec", "fork", "pipe", ``, "qx/ +/", "open" with a "|", nor any of the other things that makes being a p +erl hacker worth being.
Relying on external programs is fundamentally non-portable, even if it works much of the time. Vanilla Perl has made me very aware of just how fragile lots of the assumptions about "make", "nmake" and "dmake" are.
I agree totally that we should try to be helpful in the case of system(@list) and ensure the first argument is quoted if its not. But the semantics for system($line) are messy.
Should we do the same workaround as CreateProcess and walk the command line, joining up spaces into the first argument until we find something that can execute and then wrap that in quotes?
sub auto_quote_system { my $line = shift; my @parts = split " ", $line; my $cmd = shift @parts; while ( ! -x $cmd ) { # does -x works for file associations? $cmd .= " " . shift @parts; } return qq{"$cmd" @parts}; }
Even that's not complete. It doesn't deal well with multiple spaces in an executable path nor with commands that can't be found. And note the unexpected result or trojan potential of a program called C:\program.exe. I think that could quickly wind up with a very convoluted kludge.
I'm more comfortable saying that if you call system($line) then it's up to you to make sure that the line is valid for your OS, particularly if we can patch system and perlport docs to advise that wrapping the first argument in a quotes is a good idea.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Poll: Is your $^X an absolute path? (system @list)
by BrowserUk (Patriarch) on Aug 18, 2006 at 15:07 UTC | |
by tye (Sage) on Aug 18, 2006 at 15:21 UTC | |
by BrowserUk (Patriarch) on Aug 18, 2006 at 15:28 UTC | |
by tye (Sage) on Aug 18, 2006 at 15:40 UTC | |
|
Re^9: Poll: Is your $^X an absolute path? (system @list)
by tye (Sage) on Aug 18, 2006 at 15:13 UTC | |
by xdg (Monsignor) on Aug 18, 2006 at 16:08 UTC | |
by tye (Sage) on Aug 18, 2006 at 16:37 UTC |