Entering values to command prompt through a script/batch/ANT/Java Code etc
I want to automate an application. On calling this application (Which starts from a batch file) it shows up a command prompt window in which it asks for values.
By values I mean :-
How can I pass these values to the command prompt using any script/batch/tool/Java program?
Right now these values has to be entered manually, I want to automate this procedure. So, here I don't want to enter them manually, I want a script to do it. Is it possible? If yes, how?
This is a copy of the solution at this post, but adjusted for your particular needs. First, the "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%"
Then , the solution:
@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));
The output:
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"
链接地址: http://www.djcxy.com/p/25556.html