Shell script to input as if from command line to the java program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to input as if from command line to the java program
# 1  
Old 07-25-2012
Shell script to input as if from command line to the java program

Hi,

We are having a java server which can run on command line and once initiated, it will prompt options to enter from 0 to 5. The java program kickoff respective operation once number is entered between 0 to 5. However i want to always enter "1" and write another shell program wrapper to start this java program and provide "1" as input so that the server will perform respective operation.

can some one help me in this regard?

Thanks,
Surya
# 2  
Old 07-25-2012
Need more details, could you please describe the steps you take?
# 3  
Old 07-25-2012
Read up on "here-document". Basically:
Code:
java_command_you_want_to_feed_input_to <<EOF
1
EOF

The shell will feed the lines between the "EOF"s (can be any string, the ending string must be at the front of a line) to the command when it expects input.
# 4  
Old 07-26-2012
Thanks Gary for the reply. However below solution did not work
java_command_you_want_to_feed_input_to <<EOF
1
EOF

Once shell script started releavant java command triggering and displaying options from 0-5 continuously in an infinite loop. I had stopped it forcefully with Ctrl-c

The shell script has below code:

export CLASSPATH=$CLASSPATH:ds.jar:./lib/antlr-2.7.6rc1.jar:./lib/cglib-2.1.3.jar:./lib/ehcache-1.2.3.jar:./lib/log4j-1.2.8.jar:./lib/asm-attrs.jar:.:
java com.infronics.smssol.main.DaemonStartUp ./res/daemon_config.cfg ./res/smpp_config_file.xml <<EOF
1
EOF
# 5  
Old 07-26-2012
You'll need to study what the java program expects as input and put the appropriate responses in the here-document.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing the shell script through java program

Hi Team, Can you pls advise in java how can we call a shell script, actly I have a shell script at the following location /opt/dd/ajh.sh now I can execute this script by opening the session through putty by entering the servers details and password and then navigating to the following... (2 Replies)
Discussion started by: punpun777777
2 Replies

2. Shell Programming and Scripting

Script to read command line input and change it to some form

Hi, I want to write a small code in which script changes command line input to some form. Example script.sh a1 a2 a3 a4 ..... output should be "a1|a2|a3|....." Number of inputs in command line can be any variable (2 Replies)
Discussion started by: Raza Ali
2 Replies

3. Shell Programming and Scripting

Read input file with in awk script not through command line

Hi All, Do we know how to read input file within awk script and send output toanother log file. All this needs to be in awk script, not in command line. I am running this awk through crontab. Cat my.awk #!/bin/awk -f function test(var){ some code} { } END { print"test code" } (5 Replies)
Discussion started by: random_thoughts
5 Replies

4. Shell Programming and Scripting

Problem while Invoke Shell Script function from Java Program

Hi, I have create a Shell Script, with one function. I want to call the script file in Java Program. It working fine. but the problem is the function in the Shell Script is not executed. Please suggest me, Regards, Nanthagopal A (2 Replies)
Discussion started by: nanthagopal
2 Replies

5. Shell Programming and Scripting

how to execute a unix shell script from a java program

Hi All, well , i am facing this problem.. i have tried a few sample codes but there isn't any solution . could anyone please give a sample code as of how to do this... Please see the below details...and read the details carefully. I have written some code, logic is 1)from... (4 Replies)
Discussion started by: aish11
4 Replies

6. UNIX for Dummies Questions & Answers

how to pass input from c program to shell script?

Hello.. I am developing a Graphical User Interface using GTK. As part of our project I need to take inputs from GTK entries and pass those inputs to shell script and use them in shell script. The problem which struck me is only limited number of inputs are getting passed to shell script. For now... (14 Replies)
Discussion started by: kalyanilinux
14 Replies

7. UNIX for Dummies Questions & Answers

Bash script to delete file input on command line

1) I wrote a script and gave the desired permissions using "chmod 755 scriptname". Now if i edit the script file, why do i need to set the permission again? Didn't i set the permission attribute.. or if i edit the file, does the inode number of file changes? 2) I am running my unix on a server... (1 Reply)
Discussion started by: animesharma
1 Replies

8. Shell Programming and Scripting

Launching a C program that needs input from a shell script

hi there, i need some help, i am trying to run a script to launch a C program and a Java program but before running both I want to get a user input and then invoke both programs with input received. In the programs the inputs are not command line arguments. This is the code, after the java... (4 Replies)
Discussion started by: momal
4 Replies

9. Shell Programming and Scripting

How can I send the input of a read line command through a shell script

Hi All, I wish to automate the unix command 'su' through a shell script. I would like to pass the content of a file as password to 'su' command. My script is as below, #! /bin/sh su userA while read line do rpm -ivh $line done < pwd.txt where pwd.txt contains the password of... (6 Replies)
Discussion started by: little_wonder
6 Replies

10. UNIX for Dummies Questions & Answers

executing the su command from a java program.

Say in unix (AIX) m/c, I am logged in with s1 user and want to start process p1 with user credentials of s2. I can do manually in this way: #su - s2 #enter password for s2> somePassword $ p1 But all this I have to do through a java program. How to pass the password through program. One... (1 Reply)
Discussion started by: shailendrat
1 Replies
Login or Register to Ask a Question