Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

IPC::Run on WindowsXP/Windows Server 2003?

by DrWhy (Chaplain)
on Jun 07, 2008 at 02:03 UTC ( [id://690790]=perlquestion: print w/replies, xml ) Need Help??

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

I'm using IPC::Run as the basis for module that overrides system() allowing you to capture output from system() calls in modules you use. It seems to be working fine on Linux, and on Windows XP/Server 2003 it works for the system(@args) form of system. However, for system($mycommandandargsinonescalar) it will not work. It seems the problem is that when an IPC::Run harness is created with just a single scalar containing a whole command line, it splits up the command into an array of command and arguments and then prepends 'command', '/c' to this list. It appears it's trying to generate a windows shell oneliner. but on all of the XP and Server 2003 machines I have there is no shell named 'command', it's 'cmd', so when you try to run the harness thus created it fails, since there is no command 'command'.

I'd appreciate any insight into what's going on here. Did older windows OS's have a command shell named 'command'? Does anyone know of a good workaround to this problem?

Thanks,

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

  • Comment on IPC::Run on WindowsXP/Windows Server 2003?

Replies are listed 'Best First'.
Re: IPC::Run on WindowsXP/Windows Server 2003?
by kabeldag (Hermit) on Jun 07, 2008 at 02:28 UTC
    Update (this is why):

    Looking inside IPC/Run.pm, the harness sub has the following:
    my @args ; if ( @_ == 1 && ! ref $_[0] ) { if ( Win32_MODE ) { @args = ( [ qw( command /c ), win32_parse_cmd_line $_[0] ] ) +; } else { @args = ( [ qw( sh -c ), @_ ] ) ; } } elsif ( @_ > 1 && ! grep ref $_, @_ ) { @args = ( [ @_ ] ) ; } else { @args = @_ ; }

    Thus, the following:
    use IPC::Run qw(run harness); # This will work my $h = harness "perl", "-v"; run $h; print "\n\n-------------------\n"; print "Calling harness with one arg..."; print "\n-------------------\n\n"; #This will not work if you don't have command.com my $h2 = harness "perl -v"; run $h2;
      Thanks for pointing that out; that's exactly the problem point. I've fixed this for now by modifying my wrapper to do this same processing (but using cmd.exe instead of command.com) before it calls IPC::Run's harness constructor so this bad line of code is never hit.

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Re: IPC::Run on WindowsXP/Windows Server 2003?
by pKai (Priest) on Jun 07, 2008 at 16:32 UTC

    I have no access to Win2k3 at the moment, but your WinXP should have a command.com.

    On my XP here:

    D:\temp>perl -e "print grep {-f $_.'/command.com'} split /;/,$ENV{PATH +}" C:\WINDOWS\system32

    Microsoft advises to "repair" your XP under such circumstances (KB324767).

    But as noted elsewhere in this thread: cmd.exe should be called by IPC::Run. Or even better $ENV{COMSPEC} maybe, which points to the primary "shell" used by an MS-OS since MS-DOS times.

Re: IPC::Run on WindowsXP/Windows Server 2003?
by syphilis (Archbishop) on Jun 07, 2008 at 02:24 UTC
    Did older windows OS's have a command shell named 'command'?

    Yes - command.com. It exists on my Windows 2000 and XP boxes (in the same folder as cmd.exe), but I don't see it on my Vista box.

    Cheers,
    Rob
      I have command.com on my 32-bit XP box and 32-bit Win2k3 box. But it is not available on 64-bit Win2k3. I don't have a 64-bit XP to check, but I would guess it's not there.

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Re: IPC::Run on WindowsXP/Windows Server 2003?
by ikegami (Patriarch) on Jun 07, 2008 at 06:14 UTC

    command.com is the 16-bit shell, dating back to the first version of DOS, as far as I know.

    cmd.exe should be used.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found