@args = ('cmd.exe', '/c', 'erase', $filename);
If Win32 had "real"™ command-line argument processing, then that wouldn't work. For example, in Unix you have to use:
and this is important in case you want to quote arguments to be given to the internal command. But going very far down that road gets rather complicated quickly so I'll leave that for another time.@args = ( 'sh', '-c', "erase $filename" );
The reason your code works is because, in Win32, system(@args) is (quite unfortunately) exactly the same as system("@args") because Win32 only deals with command lines while Unix (and C) want to deal with lists of command arguments. This can make getting the proper arguments passed in quite difficult, especially since it also means that each program parses its own command line and so you often have to prepare/quote your arguments different for different commands.
Also note that Perl will do the "cmd /c" trick for you automatically (if it can't find a "erase.*" executable in your PATH).
- tyeIn reply to Re^2: Executing DOS shell commands via system() (/c nits)
by tye
in thread Executing DOS shell commands via system()
by Grygonos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |