in reply to IPC::Run3 error

Three problems.

Solution:

$cmd = 'find -type f | p4 -x - add';

Replies are listed 'Best First'.
Re^2: IPC::Run3 error
by Anonymous Monk on Mar 10, 2011 at 08:07 UTC
    Confirmed, gnuwin32 provides a dir.EXE, where as dir is a cmd.exe/command.com built-in
    $ set IPCRUN3DEBUG=999 $ perl -MIPC::Run3 -e "run3 [qw! C:/PROGRA~1/gnuwin32/bin/dir.EXE /b / +s /a-d | cat !], undef,\*STDOUT,\*STDERR" run3(): running 'C:/PROGRA~1/gnuwin32/bin/dir.EXE' '/b' '/s' '/a-d' '| +' 'cat' run3(): redirecting stdout to filehandle 'GLOB(0x9ba4ec)' binmode STDOUT, :crlf run3(): redirecting stderr to filehandle 'GLOB(0x9ba52c)' binmode STDERR, :crlf C:/PROGRA~1/gnuwin32/bin/dir.EXE: /b: No such file or directory C:/PROGRA~1/gnuwin32/bin/dir.EXE: /s: No such file or directory C:/PROGRA~1/gnuwin32/bin/dir.EXE: /a-d: No such file or directory C:/PROGRA~1/gnuwin32/bin/dir.EXE: |: Invalid argument C:/PROGRA~1/gnuwin32/bin/dir.EXE: cat: No such file or directory run3(): $? is 512

      Ah, so you are using WinXP, it's just that you have a poorly named tool installed. Let me qualify my earlier post.


      Three problems.

      • You are using options that would be understood by Windows's dir command, which means you're not running Windows's dir command.

        The dir command is a builtin shell command. It can only be run from within a shell. Since you're not running a shell since you're using the multiple argument form of system, the right dir will never be found.

      • You're trying to run a shell command (a pipe). Since you're not running a shell since you're using the multiple argument form of system, that's not going to work.

      • You broke up the shell command into bits. How is the shell suppose to execute it?

      Solution:

      $cmd = 'dir /s/b/a-d | p4 -x - add';

      which is short for

      $cmd = ['cmd', '/c', 'dir /s/b/a-d | p4 -x - add'];

      Well, it's suppose to be. The latter doesn't work for some reason.

      Update: Removed extraneous quotes that caused the problem identified in the reply.

        I am not the OP.

        While system @$cmd will work, run3 will fail with

        '""""dir' is not recognized as an internal or external command, operable program or batch file.
        even if you hardcode a path to cmd.exe

        Yeah, "hum." This is exactly what I was hoping to use run3 for, to run cmd.exe /u /c dir $filespec. It seems that, of the myriad ways that one might attempt to get a glob of Unicode filenames in Perl for Windows, approximately 0% of them work.

Re^2: IPC::Run3 error
by chrestomanci (Priest) on Mar 10, 2011 at 13:40 UTC

    Point of clarification:

    I think the OP probably does not know that if you pass a scalar to system (or exec) then the shell is involved, but if you pass an array, then the shell get's bypassed, and the named command is run directly.

    eg, This will pass the entire command string to the shell, which will in turn invoke find, and setup a pipe to send the output to p4.

    system('find -type f | p4 -x - add')

    You might try this, but it would not work, as the find command would receive all the other arguments, and would not know how to process anything after the pipe character.

    system('find', '-type', 'f', '|', 'p4', '-x', '-', 'add')

    Back to the OP's question. Under windows, the DIR command is a shell built in, so in order to invoke it, you must invoke the shell. There is not DIR.exe system file that could be invoked outside the shell.

      Except that there is, and it comes from gnuwin32, and its the cause of the error messages "dir: /b: No such file or directory " ...

        The garbage he's giving to it (e.g. "/b") is the cause of the error messages.

        If he invokes dir through a shell, the shell builtin would be invoked, and it takes "/b".

        If he invokes dir dircetly, the gnuwin32 executable would be invoked, and it doesn't take "/b".