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

  • 相关阅读:
    Android 布局中 如何使控件居中
    VGA, QVGA, HVGA, WVGA, FWVGA和iPhone显示分辨率
    [转+整理] Android 分辨率,密度,像素单位说明
    多线程的知识点总结
    集合的相关信息
    spring cloud详解
    iostat实时监控磁盘util
    Jenkins安装过程
    hdfs的block为什么设置成128M
    shell变量自增的几种方式
  • 原文地址:https://www.cnblogs.com/firtree/p/3894608.html
Copyright © 2011-2022 走看看