aspose file tools*
The moose likes Java in General and the fly likes Executing Unix Command Through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executing Unix Command Through Java" Watch "Executing Unix Command Through Java" New topic
Author

Executing Unix Command Through Java

Aulia Yusuf
Greenhorn

Joined: Jan 04, 2007
Posts: 2
Hi,

I am trying to run some unix command through:

Runtime.getRuntime().exec("some unix command line");

I am running the code on Linux platform. However, I always got some errors. Here are the stack trace of them:

java.io.IOException: Cannot allocate memory
java.io.IOException: java.io.IOException: Cannot allocate memory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:429)
at java.lang.Runtime.exec(Runtime.java:326)



Anybody has any idea why is this happening? Thanks.
Aulia
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
You can try using ssh library of java (like http://javassh.org/) to connect to the remote server and read the log file and process it. I don't think you can fork a process remotely otherwise.
Aulia Yusuf
Greenhorn

Joined: Jan 04, 2007
Posts: 2
No, I am locally executing the command. In addition to that, I cannot even execute something simple like "ls". I am also doing it in a tight loop, but each loop throws the exception.

The code looks like this:



Please let me know if anyone has ideas why such simple code like this throws the Exception. Thanks.
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
checkout this: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing Unix Command Through Java