Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: redirecting stdin on windows

by defyance (Curate)
on Aug 20, 2002 at 18:31 UTC ( [id://191551]=note: print w/replies, xml ) Need Help??


in reply to redirecting stdin on windows

Well, I don't like to give it away, but i'll try to point you in the right direction:
#!/path/to/perl -w use strict; my $uname; my $passwd; print "username:"; chomp($uname = <STDIN>); #catch stdin, get rid of trailing newline print "Your Username is: $uname"; #print it out print "password:"; chomp($passwd = <STDIN>);

Alternativly, if your wanting to pass these vars to another program, you could do this:

#!/path/to/perl -w use strict; my $uname; my $passwd; print "username:"; chomp($uname = <STDIN>); print "password:"; chomp($passwd = <STDIN>); system("/path/to/prog", "$uname", "$passwd");

It all depends on what you want to do with it, if you wanna elaborate on what it is you want to do, we could help with it, there's just some basic ideas. Also, you say you are new to Perl, You should check out the Tutorials, also, a book called "Learning Perl", an O'reilly Book, devoted to learning the rich language we call Perl.

UPDATE:Fixed a syntax error, heh.

--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--

perl -e '$a="3567"; $b=hex($a); printf("%2X\n",$a);'

Replies are listed 'Best First'.
Re: Re: redirecting stdin on windows
by arkamedis21 (Acolyte) on Aug 20, 2002 at 18:47 UTC
    No I don't want to write a program that gets the username or password, there is this program there already that runs interactively, which prompts the user fro a username and a password. I was trying to get a way to pass a username and a password from a perl script to this executable. This executable doesn't take any command line options and runs interactively as I have shown above.

    I tried doing the following, but it fails for some reason:

    open (FIFO, "$program |");
    print FIFO "$username\n";
    print FIFO "$passwd\n";
    print FIFO "$passwd\n";
    print FIFO "y\n";
    close FIFO || die "error closing redirector \n";


    The program looks like the following again. <BR
    username :
    password :
    confirm :
    Do you want the action to be persistent (y/n) :

    The code I have above doesnt run well for some reason. I am trying to make it so the user runs the perl script and doesnt see any output by this program, and the perl script enters the username and password for him.
      I meant

      open (FIFO, "| $program");
      Woah, okay, lets see, what exactly is in $program? and why are you open();ing it, your not going to be able to send anything to $program unless you do something like this:
      open(FIFO), ">$program") || die "Darn : $!"; #will give you a good rea +son why it can't open. the ">" says, write to this file. print FIFO "$username\n"; and so on.....
      Thats assuming that $program is a writable file, and your printing the values to it..

      Am I misunderstanding what you are trying to do?

      --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--

      perl -e '$a="3567"; $b=hex($a); printf("%2X\n",$a);'

        hmph, you mean |$program dont you? or do you really want him to overwrite the program? =)

        -Waswas
        $program has the path name to my executable. I am trying to open a pipe to that executable. Please look at

        perldoc perlipc

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-25 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found