Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-28-2011, 03:22 AM   #1
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>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 after revision the command comes out to be

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

It still dosent 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, 06:15 PM   #2
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
Process p=Runtime.getRuntime().exec("sh ./");
Old 03-01-2011, 02:23 AM   #3
LQ Newbie
Registered: Feb 2011
Posts: 2

Original Poster
Rep: Reputation: 0

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!!


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 11:04 AM
Running bash but common bash commands not working michellepace Linux - Newbie 11 07-17-2010 10:19 AM
Running Linux Commands in Java jcafaro10 Programming 3 04-15-2009 01:10 PM
Installing java runtime env problem ur-unholyness Linux - Software 2 04-10-2005 02:32 AM
java runtime problem iamedu Programming 2 09-23-2004 07:00 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:18 PM.

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