copy stdout fails with permission denied when stdout is redirected

  • Thread starter brian.mabry.edwards
  • Start date
B

brian.mabry.edwards

Running Windows XP / ActivePerl v5.8.7

The following combination causes a permission denied failure:
* duplicate stdout in my script
* redirect stdout on command line
* run script with "name" instead of "perl name.pl"

I did the following to allow me to execute the script by name
* assoc .pl=Perl
* ftype Perl=c:\Perl\bin\perl.exe %1 %*
* set PATHEXT=%PATHEXT%;.pl

Simple example showing the failure.

testRedirect.pl

open(OUTCOPY, ">&STDOUT") or die "Couldn't dup STDOUT: $!";
close OUTCOPY;
print "Success!\n";

Works this way

C:\>perl
C:\da_home_eclipse30\NIL\test\regression-tests\bin\testRedirect.pl
tmp\out.txt

C:\>type tmp\out.txt
Success!

And it works this way

C:\>testRedirect
Success!

Fails this way

C:\>testRedirect >tmp\out.txt
Couldn't dup STDOUT: Permission denied at
C:\da_home_eclipse30\NIL\test\regression-tests\bin\testRedirect.pl line
1.

Is there anything I can do to get this to work?
 
U

usenet

Is there anything I can do to get this to work?

Sorry, it's really unclear exactly what you are trying to do. It looks
like you just trying to capture the output (STDOUT) of a Perl script to
a file - is that correct? cuz' you don't need to do any of that stuff
you're doing...
 
A

A. Sinan Unur

Running Windows XP / ActivePerl v5.8.7

The following combination causes a permission denied failure:
* duplicate stdout in my script
* redirect stdout on command line
* run script with "name" instead of "perl name.pl"

I did the following to allow me to execute the script by name
* assoc .pl=Perl
* ftype Perl=c:\Perl\bin\perl.exe %1 %*
* set PATHEXT=%PATHEXT%;.pl

Simple example showing the failure.

testRedirect.pl

open(OUTCOPY, ">&STDOUT") or die "Couldn't dup STDOUT: $!";
close OUTCOPY;
print "Success!\n";

Works this way

C:\>perl
C:\da_home_eclipse30\NIL\test\regression-tests\bin\testRedirect.pl

C:\>type tmp\out.txt
Success!

And it works this way

C:\>testRedirect
Success!

Fails this way

C:\>testRedirect >tmp\out.txt
Couldn't dup STDOUT: Permission denied at
C:\da_home_eclipse30\NIL\test\regression-tests\bin\testRedirect.pl
line 1.

Is there anything I can do to get this to work?

I don't think so. I think it is related to the following behavior:

#!/usr/bin/perl

use strict;
use warnings;

print while <>;
__END__

D:\Home\asu1\UseNet\clpmisc> tt < Test.java

D:\Home\asu1\UseNet\clpmisc>

That is, not output is produced.

Whereas

D:\Home\asu1\UseNet\clpmisc> perl tt.pl < Test.java

works as expected.

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top