1

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 :-

  1. First, it will ask you to hit ENTER (Can ENTER be automated?)
  2. Then it asks for a path (String, of course)
  3. Then it asks again for another path (String, again)

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?

Ravish Rawat
  • 476
  • 2
  • 15
  • 48
  • Did you mean like a menu ? can you edit your post and add your code ? – Hackoo Jun 25 '15 at 11:08
  • 1
    This should help you: http://stackoverflow.com/questions/17038282/press-keyboard-keys-using-a-batch-file – MichaelS Jun 25 '15 at 11:12
  • check this - https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/sendKeys.bat – npocmaka Jun 25 '15 at 11:16
  • 1
    Please narrow your question to one technology: Script or Batch file or an Ant script or a Java program. – Chad Nouis Jun 25 '15 at 14:12
  • possible duplicate of [How do I prompt for input in a Linux shell script?](http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell-script) – Stavr00 Jun 25 '15 at 14:37
  • 1
    For ANT you can use the `input` task. For Windows CMD you can use the `SET /P` – Stavr00 Jun 25 '15 at 14:37

1 Answers1

6

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:\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));

The output:

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"
Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108