wood burning stoves 2.0*
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
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: 41096
    
  44
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?
 
Similar Threads
Runtime getRuntime() exec(String command) - How does this work?
Running a .bat/ .cmd file from Java
executing scripts
Runtime.getRuntime().exec(somecommand) -help
Mysql database restore through java application...?