in reply to Re: redirecting stdin on windows
in thread redirecting stdin on windows

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.

Replies are listed 'Best First'.
Re: Re: Re: redirecting stdin on windows
by arkamedis21 (Acolyte) on Aug 20, 2002 at 18:51 UTC
    I meant

    open (FIFO, "| $program");
Re: Re: Re: redirecting stdin on windows
by defyance (Curate) on Aug 20, 2002 at 19:21 UTC
    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
        Nice catch, you can also append to the program using open(FIFO, ">>$program");

        Check out:open

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

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

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

      perldoc perlipc
        Wow, once more, lack of sleep rears its ugly head and makes my eyes deceive me.

        Please forgive me, I'm going to take a nap now.

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

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