Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Executing shell commands in Java

Hi

I have managed to get my Java program to execute the 'who' command and read in the data from running that command. However, how can I run this command with the '-m' option. I thought it would be

Process proc = rt.exec("who -m");

However when I run this, I get no data. Is there another way of running this command.

Many thanks

Sambo
[400 byte] By [sboothman] at [2007-11-11 10:28:54]
# 1 Re: Executing shell commands in Java
try putting "sh" "who" "-m" in a String array and call the Runtime.exec() method

String str[] = {"sh","who","-m"};
rt.exec(str);
sudheerprem at 2007-11-11 22:31:30 >
# 2 Re: Executing shell commands in Java
Thanks, I will give that a go, but I think it may be something to do with the argument type, as the method works with other arguments, just not this one.
Thanks Again

Sambo
sboothman at 2007-11-11 22:32:30 >