Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: System call in Windows

by blazar (Canon)
on Oct 25, 2008 at 13:21 UTC ( #719501=note: print w/replies, xml ) Need Help??

in reply to Re^2: System call in Windows
in thread System call in Windows

Thanks that worked great! Can you tell or point me to somewhere where it explains the weirdness. Thanks again!

I personally believe that there's no weirdness at all: system either wants a single string as an arguments list, or a several ones. In the former case, the string is parsed for shell metacharachters and if any, it is processed by the system's shell, otherwise, it is split up in "words" and executed directly by the suitable system call. The same happens in the latter case, directly. Now, your code as you posted in the root node is

system(perl -pib -e "s/CAT/mouse/g" 'D:\tmp\file.txt');

which would seem to fall in the second category, but most importantly contains many barewords: these should be disallowed at all if you're running under strict and you know you should run under strict except perhaps with the simplest oneliners. There should be no difference between operating systems wrt this issue. Moreover, the barewords are not separated by commas which also would make for a Perl syntax error irrespective of the OS, and strict too. All in all, you seem to think that whatever is an argument to system() doesn't need any quoting, as if perl itself were a shell, but that's not the case. You either want:

system qq|perl -pib -e "s/CAT/mouse/g" 'D:\tmp\file.txt'|;

(in which I used alternate delimiters on the outer string not to have to quote double quotes inside it) or

system 'perl', '-pib', '-e', '"s/CAT/mouse/g"', q|'D:\tmp\file.txt'|;

Incidentally, since no argument contains spaces, you may rewrite the latter like

system qw|perl -pib -e "s/CAT/mouse/g" 'D:\tmp\file.txt'|;

but pay attention in the general case! Whatever, in both cases you may have an OS quoting problem: you're giving perl a cmd line argument of 'D:\tmp\file.txt' which it will interpret literally as a filename, much different from D:\tmp\file.txt as you can see for yourself:

C:\temp>perl -lpe "" foo.txt foo bar C:\temp>perl -lpe "" 'foo.txt' Can't open 'foo.txt': No such file or directory.
If you can't understand the incipit, then please check the IPB Campaign.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-11-23 21:35 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (340 votes). Check out past polls.