in reply to Re: system() implementation on Windows (again)
in thread system() implementation on Windows (again)

OK, I understand what you're saying. And it is an interesting observation, which I didn't take into account so far. On the other hand, I observed this behavior also with other executables. In fact, my actual problem is related to another (specific) program, and I used the msg.exe really just to have something simple to demonstrate the issue in a post in this forum. In particular, I noticed that double quotes characters inside one of the passed arguments can destroy the whole execution. Which makes me think, that there is "something" interpreting the arguments, instead of purely passing the argument string "as is" to the executable, at the desired argument position. Anyway, thanks for your feedback!
  • Comment on Re^2: system() implementation on Windows (again)

Replies are listed 'Best First'.
Re^3: system() implementation on Windows (again)
by Anonymous Monk on Aug 18, 2011 at 20:48 UTC

    Which makes me think, that there is "something" interpreting the arguments, instead of purely passing the argument string "as is" to the executable, at the desired argument position.

    Yeah, its called

    $ perl -V:sh sh='cmd /x /c';
      Well... On a unix system it says:
      $ perl -V:sh sh='/bin/sh';
      But that's exactly my point. This variable should not matter when using system() in the "argument array format". According to official perl documentation, when you use system() in the format:
      system('command line with some args and special characters');
      then this might involve calling a local shell. But when you call system() in the format:
      system('executable', 'arg1', 'arg2', 'arg3');
      then NO shell should be executed. Only the executable should be run getting the args as they are specified.

      As far as I know, on Unix the C-library function 'execv' gets called for this. And it works perfectly well. Even if any of the argN contains special characters or shell metacharacters.

      Now... I know that Windows is not Unix, and that on Windows there is no such thing as 'execv'. But even then, I would expect that something similar exists in the OS kernel, and that the Perl implementors (I mean: creators of Perl packages for Windows) are able to run the program, that I specify in the system() call, and pass it my arguments exactly as I specify them at their exact specified positions.

      So I'm wondering... Is system() implemented badly on windows ? Or is there really no way in Windows OS to achieve the same behaviour as on Unix (i.e. to make system() simply execute the executable and pass it a stack of arguments) ??