Re: Runtime exec (again)
Hi, The shutdown command now works OK. There have been a few issues with this that I didn't have in the right combination. The Tomcat service must have suitable permissions. To do this: - Under control panel select Admin tools -> Services - Right click Apache Tomcat service and select properties - Select the logon tab - Under 'This account' select a user account with administrator role. Not that Windows 2K doesn't come with a shutdown command. There is one supplied with the Win2K resource kit. - The command must be run from the overloaded exec method that takes a String array as it will not work declared as a string. - Both output and error streams must be read otherwise the process will hang. (see http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html) - The code will not run from a batch file. Thanks for your help. Andy _ Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Runtime exec (again)
Actually, take a look at: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -- Jeanfrancois Shapira, Yoav wrote: Hi, You would also want to give the full path to cmd.exe possibly, depending on how you launch Tomcat. Yoav Shapira http://www.yoavshapira.com -Original Message- From: andy wix [mailto:[EMAIL PROTECTED] Sent: Thursday, December 02, 2004 4:12 AM To: [EMAIL PROTECTED] Subject: Runtime exec (again) Hi, Still can't get this to work. There must be some reason why this won't run under Tomcat but does work stand-alone. To recap, I am trying to execute the following code on an Xp box with Tomcat 5.0.27: Process proc = runtime.exec("cmd.exe /C shutdown -r -f -m \\myPC -t 50"); int exitVal = proc.waitFor(); When this runs the proc exits with a value of 0 but nothing happens (no re-boot) and no exceptions are thrown. I have tried running the code from a batch file and without the cmd.exe /C bit. I have tried running Tomcat from the command line (not as service). I have tried allowing all permissions in the catalina.policy file: grant codeBase "file:${catalina.home}/webapps/ROOT/WEB-INF/classes/-" { permission java.security.AllPermission "*"; }; I CAN successfully set the the system time and date using the same approach though. I have absolutely no idea on this now. Thanks, Andy _ Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Runtime exec (again)
Hi, You would also want to give the full path to cmd.exe possibly, depending on how you launch Tomcat. Yoav Shapira http://www.yoavshapira.com >-Original Message- >From: andy wix [mailto:[EMAIL PROTECTED] >Sent: Thursday, December 02, 2004 4:12 AM >To: [EMAIL PROTECTED] >Subject: Runtime exec (again) > >Hi, > >Still can't get this to work. > >There must be some reason why this won't run under Tomcat but does work >stand-alone. >To recap, I am trying to execute the following code on an Xp box with >Tomcat >5.0.27: > >Process proc = runtime.exec("cmd.exe /C shutdown -r -f -m \\myPC -t 50"); >int exitVal = proc.waitFor(); > >When this runs the proc exits with a value of 0 but nothing happens (no >re-boot) and no exceptions are thrown. > >I have tried running the code from a batch file and without the cmd.exe /C >bit. > >I have tried running Tomcat from the command line (not as service). > >I have tried allowing all permissions in the catalina.policy file: >grant codeBase "file:${catalina.home}/webapps/ROOT/WEB-INF/classes/-" { > permission java.security.AllPermission "*"; >}; > >I CAN successfully set the the system time and date using the same approach >though. > >I have absolutely no idea on this now. > >Thanks, >Andy > >_ >Express yourself with cool new emoticons >http://www.msn.co.uk/specials/myemo > > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Runtime exec (again)
On Thursday 2 December 2004 09:12, andy wix wrote: > Hi, > > Still can't get this to work. > > There must be some reason why this won't run under Tomcat but does work > stand-alone. > To recap, I am trying to execute the following code on an Xp box with > Tomcat 5.0.27: > > Process proc = runtime.exec("cmd.exe /C shutdown -r -f -m \\myPC -t 50"); > int exitVal = proc.waitFor(); > > When this runs the proc exits with a value of 0 but nothing happens (no > re-boot) and no exceptions are thrown. This is just an idea, it might be completely wrong, but it could be to do with StringTokeniser. Runtime.exec(String) uses StringTokeniser to parse the string into tokens, and you might find that it works better if you do it yourself and use Runtime.exec(String[]) -- Edward Barrow Copyright Consultant (and amateur programmer) [EMAIL PROTECTED] ***Important: see http://www.copyweb.co.uk/email.htm for important information about the legal status of this email - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Runtime exec (again)
Hi, I can't test this because shutdown is only a command on Windows XP it seems ... that's what you're running right? I did however try ipconfig and that works .. <% try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("cmd.exe /C ipconfig"); int exitVal = proc.waitFor(); BufferedInputStream bis = new BufferedInputStream(proc.getInputStream()); byte[] streamBuffer = new byte[4096]; int byteRead = -1; while ((byteRead = bis.read(streamBuffer)) > - 1) { out.print(new String(streamBuffer, 0, byteRead)); } } catch (Exception e) { System.out.println(e.getMessage()); } %> I can have a look when I get home tonight on my XP machine if you have not sorted it by then. Cheers, Allistair. > -Original Message- > From: andy wix [mailto:[EMAIL PROTECTED] > Sent: 02 December 2004 09:12 > To: [EMAIL PROTECTED] > Subject: Runtime exec (again) > > > Hi, > > Still can't get this to work. > > There must be some reason why this won't run under Tomcat but > does work > stand-alone. > To recap, I am trying to execute the following code on an Xp > box with Tomcat > 5.0.27: > > Process proc = runtime.exec("cmd.exe /C shutdown -r -f -m > \\myPC -t 50"); > int exitVal = proc.waitFor(); > > When this runs the proc exits with a value of 0 but nothing > happens (no > re-boot) and no exceptions are thrown. > > I have tried running the code from a batch file and without > the cmd.exe /C > bit. > > I have tried running Tomcat from the command line (not as service). > > I have tried allowing all permissions in the catalina.policy file: > grant codeBase "file:${catalina.home}/webapps/ROOT/WEB-INF/classes/-" { permission java.security.AllPermission "*"; }; I CAN successfully set the the system time and date using the same approach though. I have absolutely no idea on this now. Thanks, Andy _ Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- QAS Ltd. Developers of QuickAddress Software http://www.qas.com";>www.qas.com Registered in England: No 2582055 Registered in Australia: No 082 851 474 --- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]