in reply to Re^5: quoting issue with system command (Win32)
in thread quoting issue with system command

system(@list) bypasses the shell under Unix (and similar OSes) because system uses the Unix-like shell in order to parse command-line arguments. Under Win32, using the shell (cmd.exe) is done for other reasons. In both environements, I/O redirection is something that the shell is used for.

In Win32, cmd.exe is also used for getting at quite a few "internal" commands including "echo", "dir", "copy", and "move". So even if you don't have any "shell meta characters", cmd.exe will get invoked if trying to run the command without it fails (basically).

ActiveState doesn't maintain Perl source code. The code in question is very likely in http://cpansearch.perl.org/src/NWCLARK/perl-5.8.9/win32/win32.c, for example.

- tye        

Replies are listed 'Best First'.
Re^7: quoting issue with system command (internals)
by John M. Dlugosz (Monsignor) on May 15, 2009 at 15:38 UTC
    The brain-dead CMD.exe shell doesn't do as much or as fancy of I/O redirection as Perl's syntax supports. Are you sure it doesn't set up the handles before calling CreateProcess?

    So, the command is tried directly first, and if that fails, it tries it through CMD.EXE (I already know that it ignores COMSPEC and always uses the default system shell). There is a further issue of separating out the program name/specification from the command tail.

    If multiple arguments are used, I would expect it to simply use the first arg as the ApplicationName. If passed one string, it needs to parse out the first argument the same way a command-line user would expect.

    I can see the "indirect object" form is possible as well, using the indirect object as the ApplicationName which may be different from the first param in the string.

    —John