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

I guess what I learned about it is out of date, too.

His example used "echo", which is something I expect of CMD.exe, not something that works with CreateProcess.

I looked at the source, and can't make heads nor tails of it. I can't find the ActiveState source on their site anymore, so I looked at the generic perl source.

So, does it always run the shell? I thought the list form would bypass it. I think it's high time that we update the docs with what really happens.

—John

  • Comment on Re^5: quoting issue with system command (Win32)

Replies are listed 'Best First'.
Re^6: quoting issue with system command (internals)
by tye (Sage) on May 13, 2009 at 22:48 UTC

    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        

      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