通过 script/batch/ANT/Java 代码等向命令提示符输入值

Entering values to command prompt through a script/batch/ANT/Java Code etc

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

我的意思是值:-

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

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

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

这是 this post 中解决方案的副本,但已根据您的特定需求进行了调整。首先,"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:\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));

输出:

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"