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. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-31-2010, 05:52 AM
|
#1
|
|
LQ Newbie
Registered: Aug 2010
Location: jalandhar
Distribution: any
Posts: 11
Rep:
|
prbm in java with bash scripting
hi i am using java in RHEL5. i am using front end as java and back end RHEL5.
i am trying to calling a bash script with java. but i am facing problem.
i am using following java coding to use call the bash script
import java.util.*;
import java.io.*;
public class b
{
public static void main(String[] args)
{
try {
Process child = Runtime.getRuntime().exec("/bin/bash");
BufferedWriter outCommand = new BufferedWriter(new OutputStreamWriter(child.getOutputStream()));
outCommand.write("sh ftp.sh"); //my script file name
outCommand.flush();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
but if i am having normal script like create files etc then it will run.
but i am having some scripts which take input from user then it will not work
for e.g if my script file ftp.sh is
#!bin/bash
read -p "enter value:" var
then it will not work .
so please suggest me the way to execute this script.
|
|
|
|
11-01-2010, 01:10 AM
|
#2
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
No. You should be doing something like this:
Code:
Process process = Runtime.getRuntime().exec("your command");
// Now read/write data with the PROCESS streams!
http://download.oracle.com/javase/1....g/Process.html
PS:
I suggested it last August, and I'm suggesting it again now: if you want to interact with your server remotely (as I believe it sounded like you wanted to do back then), and you want to program your logic in Java, then I *strongly* urge you to consider using Apache/Tomcat.
IMHO...
Last edited by paulsm4; 11-01-2010 at 01:14 AM.
|
|
|
|
11-01-2010, 12:20 PM
|
#3
|
|
LQ Newbie
Registered: Aug 2010
Location: jalandhar
Distribution: any
Posts: 11
Original Poster
Rep:
|
Thanks for the reply
this command although run the normal script file,but not the script having command like read etc.
so my problem is that.
my script file containing the read command. and i want to execute this script file.
|
|
|
|
11-01-2010, 12:22 PM
|
#4
|
|
LQ Newbie
Registered: Aug 2010
Location: jalandhar
Distribution: any
Posts: 11
Original Poster
Rep:
|
And sir i have only knowledge of core java,so i dont know how to use tomcat,apache etc
|
|
|
|
11-01-2010, 01:04 PM
|
#5
|
|
Senior Member
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 3,669
|
Quote:
Originally Posted by arun8900
And sir i have only knowledge of core java,so i dont know how to use tomcat,apache etc
|
Uhm, then learn them?
Last edited by dugan; 11-01-2010 at 01:05 PM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:53 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|