aspose file tools*
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 Spring in Action this week in the Spring 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: 42277
    
  64
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to execute a command from Java in Linux?