1

I am just stuck at thing scenario,

I have a batch file which upon running will ask for confirmation like " press y/n ". Now i am to automate that batch file using ant. so, my code looks something like this

<exec executable="cmd.exe" dir="${base.dir}" >
  <arg line="/c run.bat" />
</exec>

but I have no idea how to pass the keyboard value 'y' to it in run time please help me out

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121

3 Answers3

0

Just provide /y input as you would without ant:

<exec executable="cmd.exe" dir="${base.dir}" >
  <arg line="/c run.bat /y "/>
</exec>

Another way is to use inputstring task.

E.g.:

<exec executable= "run.bat" failonerror="true" inputstring="Y">
</exec>

However this proved to be unstable in some scenarios.

Do-do-new
  • 794
  • 8
  • 15
0

Use the input task?

dbreaux
  • 4,982
  • 1
  • 25
  • 64
  • Ah, the bat file itself is doing the prompting. Got it. Thought you wanted to replace bat file's prompting with Ant prompting. (Is that an option?) That may not be possible. See [this question](http://stackoverflow.com/questions/4176305/ant-exec-task-how-can-i-read-input-from-console-stdin) – dbreaux Jul 21 '11 at 13:58
  • hmmmm, got a workaround. But it is not that effective. well, thank U. – Sai Ganesh Pittala Jul 21 '11 at 18:47
0

Use combination of input task and inputstring parameter of exec task.

<input
  message="All data is going to be deleted from DB continue (y/n)?"
  validargs="y,n"
  addproperty="do.delete"
/>

<exec
  executable="cmd.exe"
  dir="${base.dir}"
  inputstring="${do.delete}"
>
  <arg line="/c run.bat" />
</exec>
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121