通过脚本/batch/ANT/Java代码等在命令提示符下输入值



我想自动化一个应用程序。在调用该应用程序(从批处理文件开始)时,它会显示一个命令提示符窗口,在其中询问值。

我的意思是:-

  1. 首先,它会要求您点击ENTER(ENTER可以自动执行吗?)
  2. 然后它要求一个路径(当然是字符串)
  3. 然后它再次请求另一个路径(字符串,再次)

如何使用任何脚本/batch/tool/Java程序将这些值传递到命令提示符?

现在这些值必须手动输入,我想自动化这个过程。所以,在这里我不想手动输入它们,我想要一个脚本来完成。这可能吗?如果是,如何?

这是本文中解决方案的副本,但根据您的特定需求进行了调整。首先,"application.bat":

@echo off
set /P "=Hit ENTER to continue"
set /P "aPath=Enter a path: "
set /P "anotherPath=Enter another path: "
echo/
echo I read "%aPath%" and "%anotherPath%"

然后,解决方案:

@if (@CodeSection == @Batch) @then

@echo off
echo Start the Batch file
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
rem Start the "application" in the same Window
start "" /B cmd /C application.bat
rem Wait and send the first ENTER
ping -n 2 -w 1 localhost > NUL
%SendKeys% "{ENTER}"
rem Wait and send the first path
ping -n 2 -w 1 localhost > NUL
%SendKeys% "C:Thefirstpath{ENTER}"
rem Wait and send the second path
ping -n 2 -w 1 localhost > NUL
%SendKeys% "D:ASecondPath{ENTER}"
goto :EOF

@end

// JScript section
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));

输出:

Start the Batch file
Hit ENTER to continue
Enter a path: C:Thefirstpath
Enter another path: D:ASecondPath
I read "C:Thefirstpath" and "D:ASecondPath"

相关内容

  • 没有找到相关文章

最新更新