Hi all. I am currently developing a java program that will shutdown
computers which are connected to a network. I have a function that is
able to shutdpwn the computer with a shutdown message by passing code
to the command prompt. The shutdown type that I am using for the
command prompt would be
shutdown -m \\computername -r -c "shutdown message" -f.
The -c set what the shutdown message is going to be.
If I run the program and in the box type Hello it works fine and
shutsdown the computer, however if I type Hello World it stops the
program from being able to be shutdown, however if I put HelloWorld
the programs works fine again and shuts the computer down showing the
message. It doesn't seem to like a shutdown message with spaces in.
The code that I am using to perform this shutdown is below:
try {
Runtime.getRuntime().exec("shutdown -m \\\\"+
remoteshutdown.mainScreen.lstComputerNames.getSelectedValue()+ "
-r -t 30 -f -c " remoteshutdown.mainScreen.txtShutdownMsg.getText());
} catch (Exception ex) {
System.out.println("Fail to ShutDown" + ex.toString());
}
Any help in this matter would be highly appreciated.
Thank you
Real Gagnon - 30 Aug 2007 22:42 GMT
christopher_board@yahoo.co.uk wrote in news:1188509418.398860.228520
@q4g2000prc.googlegroups.com:
> It doesn't seem to like a shutdown message with spaces in.
Try to put each element of your command line in an array.
Something like
String[] cmd = { "myProgram.exe", "-o=This is an option" };
Runtime.getRuntime().exec(cmd);
Bye.

Signature
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html
Thomas Fritsch - 31 Aug 2007 00:31 GMT
> Runtime.getRuntime().exec("shutdown -m \\\\"+
> remoteshutdown.mainScreen.lstComputerNames.getSelectedValue()+ "
> -r -t 30 -f -c " remoteshutdown.mainScreen.txtShutdownMsg.getText());
It is usually more reliable to command-splitting by yourself, instead of
letting Runtime#exec do the command-splitting. Try this:
String[] cmdArray = {
"shutdown",
"-m",
"\\\\" + remoteshutdown.mainScreen.lstComputerNames.getSelectedValue()
"-r",
"-t",
"30",
"-f",
"-c",
remoteshutdown.mainScreen.txtShutdownMsg.getText()
};
Runtime.getRuntime().exec(cmdArray);

Signature
Thomas
Roedy Green - 31 Aug 2007 05:08 GMT
>shutdown -m \\computername -r -c "shutdown message" -f.
see http://mindprod.com/jgloss/shutdown.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com