It's not right. I have several batch file running sc command and it's not a synchronous command.
When you run 'sc stop nexus-webapp' it will send termination command to the service manager and exit. It will not wait until the service itself is down. what you might want to do is: 'sc stop nexus-webapp', better not find /(error|fail)/i keep running 'sc query nexus-webapp' until the service is down (you might want to do some parsing of the STDOUT to find /STATE\s+:\s+1\s+STOPPED/) 'sc start nexus-webapp' keep running 'sc query nexus-webapp' until the service is up (/STATE\s+:\s+4\s+RUNNING/). since you don't have win box, I am sending you several responses to sc command. >sc stop SRV [SC] OpenService FAILED 5: Access is denied. >sc stop SRV SERVICE_NAME: SRV TYPE : 20 WIN32_SHARE_PROCESS STATE : 3 STOP_PENDING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x1 WAIT_HINT : 0x7530 >sc query SRV SERVICE_NAME: SRV TYPE : 20 WIN32_SHARE_PROCESS STATE : 1 STOPPED (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 >sc start SRV SERVICE_NAME: SRV TYPE : 20 WIN32_SHARE_PROCESS STATE : 2 START_PENDING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x7d0 PID : 1380 FLAGS : >sc query SRV SERVICE_NAME: SRV TYPE : 20 WIN32_SHARE_PROCESS STATE : 4 RUNNING (STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 On Wed, Aug 15, 2012 at 8:38 AM, Bill Stephenson <bi...@ezinvoice.com> wrote: > I need to write a script that runs a series of Windows commands, and I have > to wait while each performs its functions, then go on to the next command. > > I know almost nothing about Windows, and I can't test it because I don't have > a Windows box. I read up a bit and it looks to me that something like this > should work: > > > system 'C:\Documents and Settings\bill>sc stop nexus-webapp'; > > system 'C:\Documents and Settings\ bill >sc start nexus-webapp'; > > system 'C:\Documents and Settings\ bill >sc query nexus-webapp'; > > > Does that look right? Or do I need to do something more like this example: > > use POSIX ":sys_wait_h"; > > do { > system 'C:\Documents and Settings\bill>sc stop nexus-webapp'; > $kid = waitpid(-1, WNOHANG); > } while $kid > 0; > > (source: http://perldoc.perl.org/functions/waitpid.html) > > > Or am I not even close with either? > > Thanks, > > Bill > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/