copy stdout fails with permission denied when stdout is redirected

Discussion in 'Perl Misc' started by brian.mabry.edwards@gmail.com, Dec 7, 2005.

  1. Guest

    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?
     
    , Dec 7, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > 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...
     
    , Dec 7, 2005
    #2
    1. Advertising

  3. "" <> wrote in
    news::

    > 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?


    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

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Dec 7, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=

    Connection string fails - permission denied

    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=, Mar 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    458
    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=
    Mar 16, 2006
  2. Ben_
    Replies:
    0
    Views:
    345
  3. Replies:
    8
    Views:
    5,643
  4. Pappy
    Replies:
    3
    Views:
    392
  5. Dirk Loss
    Replies:
    3
    Views:
    351
    Bjoern Schliessmann
    Dec 19, 2007
Loading...

Share This Page