Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-21-2008, 04:53 AM   #1
LQ Newbie
Registered: Feb 2008
Posts: 5

Rep: Reputation: 0
executing shell script from java application

hi,i want to know is there any way of executing a shell script from my java application? please help me........
Old 02-21-2008, 05:26 AM   #2
LQ Newbie
Registered: Feb 2008
Location: Poland
Distribution: Fedora 8
Posts: 2

Rep: Reputation: 0
read about method exec() at

quick example how to execute 'ls' command

Runtime.getRuntime().exec("ls -l");

Last edited by bartekg; 02-21-2008 at 05:29 AM.
Old 02-21-2008, 12:52 PM   #3
LQ Newbie
Registered: Feb 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thank u bartekg.......
i have read the description given for runtime and i've tried executing the program as below:
Public class ExecCMD{
psvm(S a[]){
Runtime r=Runtime.getRuntime();
Process p=r.exec("sh");
}catch(Exception e){
when i run this code i didn't get the o/p as the shell should print a string.So,i have changed my shell to redirect the o/p to a file
i.e echo "abcdef" > abc.txt
so after running the above java program i got a file named abc.txt which contains the string abcdef.this shows that my shell is running.
But what my problem is, i must give input from an interface created by java
program to a shell script.(dynamically)
i' m very thankful to u
plz reply me soon
Old 02-21-2008, 10:41 PM   #4
Registered: Feb 2008
Posts: 67

Rep: Reputation: 17
One way to do it is to create a file-system pipe (man mkfifo). Have the script read from it, and have the java program write to it.
Old 02-22-2008, 02:29 AM   #5
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,707

Rep: Reputation: 416Reputation: 416Reputation: 416Reputation: 416Reputation: 416
Another way would be using the Runtime.getInput/Output/ErrorStream() methods.
Old 02-24-2008, 11:39 AM   #6
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Moved: This thread is more suitable in <PORGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
executing konsole from shell script Meriadoc Linux - Newbie 10 07-10-2009 08:08 AM
Executing a shell script command!! vishamr2000 Programming 4 08-15-2005 12:33 AM
executing shell script on apache nooodles Linux - General 1 06-29-2004 01:51 AM
1. shell script "find and replace" on text 2. java GUI application randomx Programming 4 03-05-2004 01:01 PM
executing a shell script from C llama_meme Programming 2 04-01-2002 09:10 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration