Automating a Java program using KSH

Hi Guys,

We have a java program that basically install updates to an existing software. The java program consist of several screens asking user for choices (please see below for a detailed example)

*** Screen 1 ***

Please choose the operation you want to perform:

  1. Install new instance
  2. Repair existing instance
  3. Option 3
  4. Blah Blah

*** Screen 2 ***

Please select the type of installation:

  1. Normal
  2. Install everything

etc...

What I need is a way to automate the running of this program and have a shell script mimic a user input. Unless I am missing something the codes below will not work

while read line
do
program_name $line
done < userinput.txt

Anyone have a solution for this?

Thank you very much in advance.

Unless the program in question accepts optional command-line options for automation, you're probably out of luck. There's no simple way to pipe input into a GUI like that.

Installer software frequently has poorly-documented or completely undocumented options for unattended install. 'unattended' is the magic keyword if you're picking through documentation, googling, etc. What these options are, if any, and how to use them, would be be software-dependent.

Well yeah I have tried every possible method that I know of where KSH can send something to an external program but it seems nothing works. But I am still hoping that some scripting gurus here can weave some magic :). Anyway just to clear any possible misunderstanding of the issue, I will give a cleared example.

I have a program in java which prints several questions on the screen asking the user for an input. Please take note that the program is not a GUI driven. It is a text based menu and the user have to input he corresponding number of his choices. Please see below for the example.

*** SCREEN 01 ***

Please select the corresponding number of the operation you want to perform:

  1. Install program
  2. Uninstall program
  3. Exit

*** User press 1 and goes to the second screen ***

*** SCREEN 02 ***

Please select the type of installation you wish to perform:

  1. Full installation
  2. Repair existing installation
  3. Exit

*** User press 1 and goes to third screen and so on ***

What I want to happen is to have a program that will mimic the action of the user answering the questions (i.e. pressing 1 for the first screen and 1 again for the second screen). The input file will be something like the one below.

*** INPUT FILE ***

1
1
...

I hope some of the gurus can enlighten me if this is feasible or not. Also please take note that the java program was developed by a vendor and we don't have the source code for it.

Thanks and regards.

Ok, this is just a hunch.
Assuming your input file is named "my_input_file.txt" and your Java class file is "MyJavaProgram.class", see if the following works -

cat my_input_file.txt | xargs java MyJavaProgram

Test it in a controlled environment first, *never* on a Production box.

tyler_durden

By screen I assumed you meant GUI. Please correct or affirm this assumption.

If it's actually a console, the 'expect' language may be of use to you here. It can wait for prompts etc. before putting in input.

Hi,

Thanks for the replies and I am really sorry I was not able to answer back earlier. I had to go out of town. Anyway what I meant was "console screen" (command prompt if you will). Installer program will be ran from the console and what we want is to automate this running by having a KSH script read a file containing the expected user inputs and putting it to the java program.

THanks and warm regards.