This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes How to execute a command from Java in Linux? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to execute a command from Java in Linux?" Watch "How to execute a command from Java in Linux?" New topic
Author

How to execute a command from Java in Linux?

ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85
Hi,

I am trying to execute a command from Java in linux, like this:
String cmd = ..... ;
Process x = Runtime.getRuntime().exec( cmd );

But my problem is I need to setup some shell variables for my Linux command?

How can I do that?

And I am running this Runtime.getRuntime().exec() in my own servlet.

Thank you for any tips.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
You can run the command inside of a short shell script, which would set up the shell variables, and then call the actual command.


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to execute a command from Java in Linux?