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"}

  • 相关阅读:
    在chrome插件开发中,如何executeScript多个content script文件
    [Silverlight]MVVM+MEF框架Jounce练习(1)
    EF的日期运算
    【silverlight】Silverlight TreeViw默认展开节点
    singleton pattern简单随笔
    Design pattern形象比喻
    C#简单选择排序
    回文算法
    C#插入排序
    Jquery调用存储过程实例
  • 原文地址:https://www.cnblogs.com/firtree/p/3894608.html
Copyright © 2011-2022 走看看