LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-28-2011, 02:22 AM   #1
wizard119
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Rep: Reputation: 0
Problem running Linux bash commands in JAVA using Runtime


As mentioned what i want to do is to get bash command working in JAVA.....i tried using the following

Process p=Runtime.getRuntime().exec("sh a.sh>c.txt");

I want to redirect the output of the .sh file into another text file.
Now the problem here is that the bash is treating this the things after the space after sh as an address......that is where the problem lies...
so i put the redirection operator in the sh file itself but it still dosent work....so after revision the command comes out to be

Process p=Runtime.getRuntime().exec("sh a.sh");

It still dosent work...is there any other thing that i need to do?
Im working on Fedora 7 (moonshine).

Also where would the files to be created by sh be created?
 
Old 02-28-2011, 05:15 PM   #2
sys64738
Member
 
Registered: May 2008
Location: NRW/Germany
Posts: 105

Rep: Reputation: 30
I am not an expert in JAVA but I have some question which may lead to a solution.

1. Does your script start at all?
2. In which directory does JAVA expect the script to be?
3. What is the current directory for JAVA?

If you answer no to 1 is
Code:
Process p=Runtime.getRuntime().exec("sh ./a.sh");
executed?
 
Old 03-01-2011, 01:23 AM   #3
wizard119
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Talking

Aaah...actually the code wasn't working on that particular machine....i tried,the second command,the one without the redirection operator ,out on another one n it works out just fine....and the files created are indeed created in the current working directory!

Thanks anyway!!
Later!
 
  


Reply

Tags
java, shell


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
[SOLVED] Java Woes: A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available ... chytraeus Slackware 10 11-27-2010 10:04 AM
Running bash but common bash commands not working michellepace Linux - Newbie 11 07-17-2010 09:19 AM
Running Linux Commands in Java jcafaro10 Programming 3 04-15-2009 12:10 PM
Installing java runtime env problem ur-unholyness Linux - Software 2 04-10-2005 01:32 AM
java runtime problem iamedu Programming 2 09-23-2004 06:00 PM


All times are GMT -5. The time now is 07:16 AM.

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