Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: shell redirect on windows, qx?

by BrowserUk (Pope)
on Apr 11, 2008 at 21:01 UTC ( #679857=note: print w/ replies, xml ) Need Help??


in reply to shell redirect on windows, qx?

This is perl 5.8.6/AS811 on XP:

c:\test>perl use File::Temp qw( tempfile ); use File::Spec qw( devnull ); $|=1; my $code =<<'CODE'; $|=1; print "ABC\n"; print STDERR "012\n"; print "IJK\n"; print STDERR "345\n"; print "XYZ\n"; print STDERR "678\n"; CODE # create a temporary perl script file my ($fh1, $scriptname) = tempfile( 'yap_XXXX', SUFFIX => '.pl'); print {$fh1} $code; close( $fh1 ); my $perl = $^X; my $devnull = File::Spec->devnull; print "No redirect: \n"; print qx{ $perl $scriptname }, "\n"; print "Redirect errors to devnull: \n"; print qx{ $perl $scriptname 2>$devnull }, "\n"; print "Redirect merging stderr and stdout: \n"; print qx{ $perl $scriptname 2>&1 }, "\n"; ^Z No redirect: 012 345 678 ABC IJK XYZ Redirect errors to devnull: ABC IJK XYZ Redirect merging stderr and stdout: ABC 012 IJK 345 XYZ 678

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: shell redirect on windows, qx?
Download Code
Re^2: shell redirect on windows, qx?
by doom (Deacon) on Apr 11, 2008 at 21:17 UTC

    Ah, cool. It looks like Active State perl behaves very much like a unix-box in this respect. Thanks for the reply.

      It looks like Active State perl behaves ...

      It's not down to AS perl. The redirection is done by the shell processor that is invoked by qx/backticks or system. Under AS perl that shell is the standard win32 cmd.exe.

      Other variants, such as cygwin builds and Strawberry etc. may choose to invoke a different shell. I think cygwin (as standard) uses a sh-alike, but you can probably get csh, bash or zsh that would run under cygwin. (If you must:), but you might have to configure something somewhere to get them used by default, and each has its own set of advantages and restrictions as with the *nix brethren.

      In theory, there is nothing to stop you from configuring a cygwin build to use cmd.exe, but I've no idea how.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://679857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-08-01 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (25 votes), past polls