jQuery in Action, 3rd edition
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
You can run the command inside of a short shell script, which would set up the shell variables, and then call the actual command.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to execute a command from Java in Linux?
 
It's not a secret anymore!