Solved

Executing shell script from java

Posted on 2013-06-13
4
430 Views
Last Modified: 2013-07-02
I need to execute a shell script from java code by passing the parameters. In short, the following command works perfect from a terminal and I need to get this executed from java code:

tom@tom-Inspiron-N4050:~/Downloads/myscripts$ ./test_final_6jun.sh test com/abc


In the above code "./test_final_6jun.sh" is the script and "test com/abc" is the parameter to be passed. How can I accomplish this using java code? Any help is much appreciated.
0
Comment
Question by:Sreejith22
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
Comment Utility
http://technojeeves.com/joomla/index.php/free/52-runtimeexec

Note particularly the issues around ensuring that stderr is read too and that streams are read in their own separate threads
0
 

Author Comment

by:Sreejith22
Comment Utility
I went through the complete source given here :

http://technojeeves.com/tech/IOUtils.java?86c4bfb0a87399eb914bee8fe5a99da9=fae8cb49527f3cd2a46cff237a9d3e82

Sorry,did not understand what need to be done with that code for resolving the question I posted.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
public static void outputProcessStreams(final Process p) {

Open in new window

Is what you should use at first when you've created the Process with Runtime.exec
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now