2013-03-28 96 views
0

我正在运行等待用户输入的Perl脚本。我如何获得批处理文件来运行脚本并提供输入?用于向Perl脚本提供用户输入的Windows批处理脚本

我无法修改Perl源代码来接受命令行参数。这是一个例子。

::fill.bat 
perl "lazy.pl" 
::Pause for 25 seconds tow wait for program to receive user input 
ping -n 25 -w 1000 127.0.0.1 > nul 
@Echo off 
::Want this to enter "y" when asked "Update script before using? [y]" 
Echo y 

enter image description here

回答

0

尝试管道答案到你的Perl脚本的执行。

echo y| perl "lazy.pl" 

该方法works elsewhere。我敢打赌它也可能在这里工作。


对于更复杂的脚本化交互,尝试expectexpect是一个基于TCL的脚本解释器,允许与控制台应用程序进行脚本交互。下面是一个示例Expect for Windows脚本:

spawn perl lazy.pl 
expect "Update script before using? [y]" 
exp_send "y\r" 
expect "Another question? [y]" 
exp_send "y\r" 
+0

这对多个命令行参数不起作用。必须有一个更简单的方法! – 2013-03-28 02:10:17

+0

那么,你可以自动检查提示并回答它们,或者你可以使用jscript或vbscript来发送我想要的SendKeys。 – rojo 2013-03-28 02:19:47

+0

@ user1022944 - 您需要在脚本中回答多少个问题?也许你可以用一堆'y'创建一个文本文件,每行一个,perl脚本要求的每个问题一个;然后输入answers.txt | perl“lazy.pl”'。我从来没有尝试过这样的事情,但它可能值得一试。 – rojo 2013-03-28 15:20:55