Automating a Java program using KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating a Java program using KSH
# 1  
Old 05-27-2010
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.
# 2  
Old 05-27-2010
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.
# 3  
Old 05-27-2010
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 Smilie. 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
0. 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
0. 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.
# 4  
Old 05-27-2010
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 -

Code:
cat my_input_file.txt | xargs java MyJavaProgram

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

tyler_durden
# 5  
Old 05-27-2010
Quote:
Originally Posted by maddmaster
Please choose the operation you want to perform:

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

*** Screen 2 ***
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.
# 6  
Old 05-30-2010
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Program java arguments

Hello, The arguments are strings. In my code I need them to be a different type, I do the cast but it is not feasible ... Have you any idea? Thank you (8 Replies)
Discussion started by: chercheur857
8 Replies

2. Shell Programming and Scripting

Automating execution of commands inside a program

I have a program dnapars I execute the program from command line as following: ./dnapars The program then prompts me some message as a user menu from where I have to select a series of options in the order R U Y R. And then I copy the output file (outfile) in another result file. I wrote the... (3 Replies)
Discussion started by: deeptisjains
3 Replies

3. Programming

need logic for java program

Hi All, I need to to wright a java programm for the following query. Qus: output need to genarate a number+ alphnumric sequence in java and get converted into ASCII code so that i can use mod logic on that. example Output: like 10 digit number 1AAAAAAAAA 1AAAAAAAAB 1AAAAAAAAC . .... (4 Replies)
Discussion started by: Ganesh Khandare
4 Replies

4. Shell Programming and Scripting

Executing a Java Program

I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

5. Linux

running java program question

hi, i have just written a simple hello world java program in my linux server, installed jdk ... and tried to compile and run it and it gave me some errors. please details below: # cat HelloWorld.java import java.util.*; import java.io.*; public class HelloWorld { public static void... (4 Replies)
Discussion started by: k2k
4 Replies

6. Shell Programming and Scripting

Help in automating dates in ksh script

I need to run a command at the end of a backup job and this command will produce a report of what my backup jobs have collected in the previous day. The real problem is that this binary works with absolute dates only, so I should have to modify the script every single time I need it to work. It... (1 Reply)
Discussion started by: italia1971luca
1 Replies

7. Shell Programming and Scripting

how can i run java program from any where

Hello all sorry didnt know where to post it i compiled simple program that using "System.getProperty("user.dir");" now i compiled the program under directory foo and and its running great when i do "java myapp" i included this directory in the $PATH env variable so i could see it fro any where... (1 Reply)
Discussion started by: umen
1 Replies

8. UNIX for Advanced & Expert Users

Invoke java program in different processc d

I have a simple script like this: for file in $dodfiles; do ./rundod $file done $dodfiles is an array of file names selected rundod is a script which invokes a java progrm which process a data file all the processing message logged into a log file in order to extract and analyze the... (1 Reply)
Discussion started by: liux99
1 Replies

9. Programming

Communication between a java and c++ program

Hi, I have the following problem. I have 2 programs, a java program and a c++ program. These 2 programs have to communicate with each other in full duplex mode. I want to use pipes for this communication. So when the c++ program pust something on the stdout the java program must be able to read... (4 Replies)
Discussion started by: lmnt22
4 Replies
Login or Register to Ask a Question