Results 1 to 5 of 5
- 11-09-2010, 06:04 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
Problem while redirecting script output to a file using java
Hi All ,
I was trying to execute a unix shell script and redirect the output to a file in unix machine. When i execute the below command it is working fine
/root/umdhanas/New/hello.sh >> big.txt
But when i try to do the same using java program as below:
Runtime run=Runtime.getRuntime();
Process proc=run.exec("/root/umdhanas/New/hello.sh >> big.txt");
A file by the name big.txt does not get created and redirection does not happen . Please help me how to solve this
- 11-09-2010, 06:10 AM #2
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
Please help on how to get the process id also
Also please let me know how to get the process id of the script executed from java
- 11-09-2010, 07:37 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
It is important to bear in mind that exec() does not interpret its string argument the same way a bash or other shell would. See, for example, the section "Runtime.exec() is not a command line" on page 4 of this JavaWorld article.
- 11-09-2010, 09:11 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
And that article also, conveniently, tells you how to mimic this...if I remember correctly.
-
That has to be one of the most viewed Java articles ever. A classic.
Similar Threads
-
Problem with calling php script from java file
By eldushyant in forum Advanced JavaReplies: 1Last Post: 04-28-2010, 12:56 PM -
problem with output of jar file
By nishant.4545 in forum Advanced JavaReplies: 2Last Post: 07-04-2009, 04:00 PM -
Redirecting output at Thread level
By beezerbutt in forum Advanced JavaReplies: 8Last Post: 02-14-2009, 11:19 PM -
Problem creating a Post script file
By krishnan.1000 in forum New To JavaReplies: 0Last Post: 02-14-2008, 07:15 PM -
Calling a Jython script from a Java Servlet returns incomplete output
By bthakur in forum Java ServletReplies: 0Last Post: 11-13-2007, 12:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks