Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing Unix Command Through Java

 
Aulia Yusuf
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic