
这就是我要做的。很难看,但是效果很好。
String STATE_PREFIX = "STATE : ";String s = runProcess("sc query ""+serviceName+""");// check that the temp string contains the status prefixint ix = s.indexOf(STATE_PREFIX);if (ix >= 0) { // compare status number to one of the states String stateStr = s.substring(ix+STATE_PREFIX.length(), ix+STATE_PREFIX.length() + 1); int state = Integer.parseInt(stateStr); switch(state) { case (1): // service stopped break; case (4): // service started break; }}runProcess是一个私有方法,它将给定的字符串作为命令行进程运行,并返回结果输出。正如我所说的,丑陋,但可行。希望这可以帮助。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)