|
|
| No such thing as a small change | |
| PerlMonks |
Re: system() implementation on Windows (again)by Haarg (Hermit) |
| on Aug 21, 2011 at 10:43 UTC ( #921513=note: print w/ replies, xml ) | Need Help?? |
|
There are two problems here, and other nodes have covered parts of them. First is that argument lists are always passed as a single string in Windows, as opposed to arrays on other systems. This is less of a problem than it appears, because 95% of programs use the same rules for parsing that string into an array. Roughly speaking, the rules are that arguments can be quoted with double quotes, and backslashes can escape any character. The second issue is that cmd.exe uses different quoting rules than the normal parsing routine. It uses caret as the escape character instead of backslash. The result of this is that you can't create a string that will be treated the same for both of these cases. This means you have to quote strings differently depending on if they have shell meta-characters or not. And there isn't any good way to check that without reimplementing the code to detect them that exists inside perl. So here is a routine that will quote arguments correctly to use with system: Most of this is taken from the article Everyone quotes command line arguments the wrong way. There are probably some things Perl could do better for this.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||