Solved

Executing shell script from java

Posted on 2013-06-13
4
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
ID: 39245627
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
ID: 39246654
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
ID: 39246993
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
ID: 39292939
:)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to combine two scripts 2 49
FTP Script 25 87
glassfish admin console 1 45
[bash] change filenames from file.log-ddmmyyyy to file.log-yyyymmdd 1 13
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

738 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