Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

IPC::Run3 error

by Anonymous Monk
on Mar 10, 2011 at 07:36 UTC ( [id://892353]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi - I am running into the below error when running ipc run3 using the below way,Can anyone advise the right way?

$cmd = [qw(dir /b /s /a-d | p4 -x - add)]; run3($cmd, \$stdin, \$stdout, \$stderr); print "$stderr\n"; OUTPUT:- dir: /b: No such file or directory dir: /s: No such file or directory dir: /a-d: No such file or directory dir: |: No such file or directory dir: p4: No such file or directory dir: -: No such file or directory dir: add: No such file or directory

Replies are listed 'Best First'.
Re: IPC::Run3 error
by ikegami (Patriarch) on Mar 10, 2011 at 08:00 UTC

    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.

    • 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, so how is the shell suppose to execute it?

    Solution:

    $cmd = 'find -type f | p4 -x - add';
      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.

      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 " ...
Re: IPC::Run3 error
by Corion (Patriarch) on Mar 10, 2011 at 07:45 UTC

    What OS are you using? Does the command work on the command line there?

      yes,it works perfectly fine on command line.WINXP OS.

        Is it really WinXP, or is it Cygwin?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://892353]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found