LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem running Linux bash commands in JAVA using Runtime (http://www.linuxquestions.org/questions/linux-newbie-8/problem-running-linux-bash-commands-in-java-using-runtime-865412/)

wizard119 02-28-2011 02:22 AM

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?

sys64738 02-28-2011 05:15 PM

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?

wizard119 03-01-2011 01:23 AM

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!


All times are GMT -5. The time now is 02:42 PM.