Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Using STDIN after exec() with ActiveState Perl

by Yaribz (Acolyte)
on Jun 21, 2015 at 18:59 UTC ( #1131364=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I have a problem when using exec() with ActiveState perl on Windows: it seems STDIN becomes multiplexed between the console and the perl program as soon as I call exec(). Here is a simple program to show what I mean:
use warnings; use strict; if(! $ENV{TEST}) { $ENV{TEST}=1; exec {$^X} ($^X,$0); } while(my $input=<STDIN>) { chomp($input); last unless($input); print "You typed: \"$input\"\n"; } print "Exiting\n";
And here is the output when I just launch this program and try to enter "test1", "test2", "test3", "test4", "test5", and then the empty string to exit:
D:\test>perl test.pl D:\test>test1 'test1' is not recognized as an internal or external command, operable + program or batch file. D:\test>test2 You typed: "test2" test3 'test3' is not recognized as an internal or external command, operable + program or batch file. D:\test>test4 You typed: "test4" test5 'test5' is not recognized as an internal or external command, operable + program or batch file. D:\test> Exiting
On the other hand, if I run this program on Linux it works perfectly:
~/test$ perl test.pl test1 You typed: "test1" test2 You typed: "test2" test3 You typed: "test3" test4 You typed: "test4" test5 You typed: "test5" Exiting ~/test$
Any idea about what is causing this? Is there any known workaround for this problem? Thanks.

Replies are listed 'Best First'.
Re: Using STDIN after exec() with ActiveState Perl
by LanX (Sage) on Jun 21, 2015 at 19:22 UTC
    Simple.. Drop the exec. :)

    What's your intention anyway?

    Better just use pure Perl solutions instead if depending on OS features respectively their (incomplete) emulation.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

        Ehm... What's wrong with setting $ENV{PATH} in a BEGIN block?

        update

        Providing you are not allowed to set the correct environment in the registry.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

        windows doesn't have LD_LIBRARY_PATH
Re: Using STDIN after exec() with ActiveState Perl
by Anonymous Monk on Jun 21, 2015 at 19:34 UTC

    Any idea about what is causing this? Is there any known workaround for this problem? Thanks.

    Thats just how it works when you launch a process in the background on windows, which is what exec does. Windows doesn't have exec, its "semuliated" by perl

    Either way interactive <STDIN> is weak sauce

    Sure you could go messing with Win32::Console and you might figure stuff out , but I doubt it; a more definitive answer doesn't hold my interest

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-05-20 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (73 votes). Check out past polls.

    Notices?