zoukankan      html  css  js  c++  java
  • 使用powershell监控命令行console程序并在停止时启动

    有一种C#命令行console程序,为了能看到console台的输出所以不能做成服务。为了防止这些程序自己死掉,使用powershell监控程序并重启

    #利用程序名来进行重启
    if (!(get-process | where-object {$_.mainwindowtitle -eq '管理员:  "tsiphone"'}))
    { cd C:lengshan
      C:lengshan siphone.bat }
      
      

    #如果是在命令行参数里面执行的话,那就应该适应 gwmic 来获得comandline的内容来进行区分了
    #因为正常情况下,get-process的操作是没有comandline这个属性的


    if (!(Get-WmiObject win32_process | where {$_.CommandLine -eq "`"C:phpphp.exe`"  `"C:Program Files (x86)Apache Software FoundationApache2.2htdocsdeamonigetui_deamon.php`""}))


    { cmd /c start "" "C:lengshan sgetui.bat"  }
      
    #将命令行做成bat,之后利用powershell判断进程是否存在,不存在的话,先结束对应的cmd进程,之后再利用start开启新的cmd窗口来启动php进程
    if (!(Get-WmiObject win32_process | where {$_.CommandLine -eq "`"c:phpphp.exe`"  `"C:Program Files (x86)Apache Software FoundationApache2.2htdocsdeamonapns_deamon.php`""}))
    { get-process cmd |where {$_.MainWindowTitle -eq "管理员:  `"tsiphone`""} | stop-process
      cmd /c start "" "C:lengshan siphone.bat"}

  • 相关阅读:
    设计模式12-享元模式
    设计模式11-外观模式
    设计模式10-装饰模式
    设计模式09-组合模式
    设计模式08-桥接模式
    设计模式07-适配器模式
    设计模式06-原型模式
    获取cookie信息
    JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录
    jmeter基础概念
  • 原文地址:https://www.cnblogs.com/firtree/p/3894608.html
Copyright © 2011-2022 走看看