LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
LinkBack Search this Thread
Old 10-31-2010, 05:52 AM   #1
arun8900
LQ Newbie
 
Registered: Aug 2010
Location: jalandhar
Distribution: any
Posts: 11

Rep: Reputation: 0
Angry 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.
 
Old 11-01-2010, 01:10 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
Old 11-01-2010, 12:20 PM   #3
arun8900
LQ Newbie
 
Registered: Aug 2010
Location: jalandhar
Distribution: any
Posts: 11

Original Poster
Rep: Reputation: 0
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.
 
Old 11-01-2010, 12:22 PM   #4
arun8900
LQ Newbie
 
Registered: Aug 2010
Location: jalandhar
Distribution: any
Posts: 11

Original Poster
Rep: Reputation: 0
And sir i have only knowledge of core java,so i dont know how to use tomcat,apache etc
 
Old 11-01-2010, 01:04 PM   #5
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,238

Rep: Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299Reputation: 1299
Quote:
Originally Posted by arun8900 View Post
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.
 
  


Reply

Tags
programming language


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting rpcaldeira Programming 11 10-09-2010 02:23 AM
[SOLVED] need help with bash scripting asidrain Linux - Newbie 4 09-05-2010 01:45 PM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
java -version, bash: java: command not found kirman Programming 4 03-19-2008 11:13 PM
bash scripting vadon Linux - Newbie 6 05-10-2005 04:07 AM


All times are GMT -5. The time now is 06:54 PM.

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