1.

Solve : Need to echo two inputs to a batch program?

Answer»

Hi All,

i have a perl script which will prompt for two user inputs.. Y and Y..

if it is ONE Y then i can run using below command.

ECHO Y|perl test.plx

but as it prompts for twice i need your help finding out how to input those using echo or any other command..

i tried the following as well but no luck..

@echo off
>input.txt echo Y
>>input.txt echo Y
type input.txt|perl test.plx

But this does not work too.. It takes for the first input but for the second it runs into INFINITE loop. Please help

i am doing this in DOS prompt..

Thanks,
You might try
Code: [Select]@echo off
>input.txt echo Y
>>input.txt echo Y
<input.txt perl test.plx
This uses the input redirection operator, but if the script needs any other input, it definitely wont work

just thinking, does the script stop to prompt you to enter, then you press return or do you just press Y
if just Y, then
Code: [Select]echo YY|perl test.plxshould workI tried the first option.. it dint work

Script stops to take the input.. I will type Y and enter then it continues.. see below..


blah blah
do you want to upgrade(Y/N)?
blah blah
blah blah
do u want to continue(Y/N)?
blah blah


From your first code it takes Y for the upgrade and it continues.. when it ask for NEXT Y it goes into infinite loop.. Its not a code issue as i have removed the upgrade part and tried it and it works fine with one Y
2nd input its not recognising or taking it but runs into infinte loop like below..

do u want to continue(Y/N)?
do u want to continue(Y/N)?
do u want to continue(Y/N)?
.
.
.


Please help
Thanks,
Arun
It SEEMS that perl.exe does accept piped and redirected input.

The problem now is: why doesn't the script act on the subsequent characters?

To figure that out we'd need to see the relevant portions of the perl script.Quote from: foxidrive on October 12, 2012, 04:54:53 AM

we'd need to see the relevant portions of the perl script.

Agreed. Here is a simple perl script that accepts 2 inputs from STDIN (the keyboard) waiting each time for ENTER.

$userinput1 = <STDIN>;
$userinput2 = <STDIN>;
print "User input 1 $userinput1\n";
print "User input 2 $userinput2\n";
print "OK\n";

if I do this...

@echo off
echo X> test.txt
echo Y>> test.txt
<test.txt C:\Perl64\bin\perl.exe test.pl

I get this...

User input 1 X

User input 2 Y

OK

Noting that the .plx extension is commonly used on Windows systems to associate Perl files with the Perl interpreter so, if the association exists, we can actually do this

<test.txt test.plx








Discussion

No Comment Found