通过脚本/批处理/ ANT/Java代码等输入值以命令提示符

Rav*_*wat 0 ant automation batch-file command-prompt

我想自动化一个应用程序.在调用此应用程序(从批处理文件开始)时,它会显示一个命令提示符窗口,在该窗口中要求输入值.

根据价值观我的意思是: -

  1. 首先,它会要求你按ENTER键(可以自动输入吗?)
  2. 然后它要求一个路径(当然是字符串)
  3. 然后再次询问另一条路径(String,再次)

如何使用任何脚本/批处理/工具/ Java程序将这些值传递给命令提示符?

现在这些值必须手动输入,我想自动执行此过程.所以,在这里我不想手动输入它们,我想要一个脚本来完成它.可能吗?如果有,怎么样?

Aac*_*ini 5

这是此帖子中的解决方案的副本,但根据您的特定需求进行了调整.首先,"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%"
Run Code Online (Sandbox Code Playgroud)

然后,解决方案:

@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:\The\first\path{ENTER}"

rem Wait and send the second path
ping -n 2 -w 1 localhost > NUL
%SendKeys% "D:\A\Second\Path{ENTER}"

goto :EOF


@end


// JScript section

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
Run Code Online (Sandbox Code Playgroud)

输出:

Start the Batch file
Hit ENTER to continue
Enter a path: C:\The\first\path
Enter another path: D:\A\Second\Path

I read "C:\The\first\path" and "D:\A\Second\Path"
Run Code Online (Sandbox Code Playgroud)