使用subprocess模块判断当前进程是否存在

#! /usr/bin/env python
import subprocess res = subprocess.Popen(r'ps -ef |grep java |grep -v grep |wc -l',
shell=True,
# 正确值
stdout=subprocess.PIPE,
# 错误值
stderr=subprocess.PIPE,) # 在windows 中需要使用 decode("gbk")
PID_tomcat_ADP=int(res.stdout.read().decode("utf-8").strip()) if PID_tomcat_ADP != 1:
shell_start = subprocess.Popen(r'/bin/sh /usr/local/tomcat/start.sh',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,)

使用python调用shell判断当前进程是否存在的更多相关文章

  1. python 调用shell命令三种方法

    #!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器: #!/usr/bin/env python这种用法是为了防止操作系统用户没有将pyth ...

  2. Python 调用 Shell脚本的方法

    Python 调用 Shell脚本的方法 1.os模块的popen方法 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出. > ...

  3. 用Python调用Shell命令

    Python经常被称作“胶水语言”,因为它能够轻易地操作其他程序,轻易地包装使用其他语言编写的库,也当然可以用Python调用Shell命令. 用Python调用Shell命令有如下几种方式: 第一种 ...

  4. python 调用 shell 命令方法

    python调用shell命令方法 1.os.system(cmd) 缺点:不能获取返回值 2.os.popen(cmd) 要得到命令的输出内容,只需再调用下read()或readlines()等   ...

  5. python调用shell, shell 引用python

    python 调用 shell get_line_num="wc -l as_uniq_info | awk '{print $1}'" ###get the lines of & ...

  6. python 调用 shell 命令

    记录 python 调用 shell 命令的方法 加载 os 模块, 使用 os 类 import os; os.system("ls /");

  7. Python调用shell命令常用方法

    Python调用shell指令 方法一.使用os模块的system方法:os.system(cmd),其返回值是shell指令运行后返回的状态码,int类型,0表示shell指令成功执行,256表示未 ...

  8. python 调用shell命令的方法

    在python程序中调用shell命令,是件很酷且常用的事情…… 1. os.system(command) 此函数会启动子进程,在子进程中执行command,并返回command命令执行完毕后的退出 ...

  9. Python调用shell

    今天学习了Python通过子进程调用shell,感觉教程上讲的过于繁复,有一些根本没用的功能,比如重定向输入输出,这个shell本身就支持,没有必要用Python的api.决定自己总结下. 其实总的来 ...

随机推荐

  1. understand 在windows 以及 unbuntu 下的安装

    1.win7 64位下安装 1)下载Understand.4.0.908.x64.rar. 2)解压之,直接运行里面的Understand-4.0.908-Windows-64bit.exe. 3)选 ...

  2. 升级Jenkins版本

    找到jenkins.war文件的安装目录 cd /usr/local/tomcat/tomcat1_jenkins/webapps/ 停止jenkins service tomcat_jenkins ...

  3. python去除字符串里的非数字

    filter(lambda ch: ch in ‘0123456789.’, crazystring)

  4. VS2017中VC++项目添加StringTable资源

    1.在资源视图中选择Resource.rc,右键弹出菜单,选择[添加资源] 2.在[添加菜单]对话框中选择[String Table],新建即可

  5. webstorm加载项目卡死在scanning files to index

    今天用webstorm导入项目时,需要加载node-modules文件夹,导致webstorm非常卡,页面提示scanning files to index... 网上搜到办法,记录下: 说明: 在n ...

  6. Winform按键捕获

    参考:http://blog.csdn.net/zhensoft163/article/details/4239796 下载链接 方法1:使用窗体的 KeyDown 事件 private void F ...

  7. 关于const修饰指针

    const修饰指针,一般分为如下四种情况: int b = 500; const int *a = &b;   //情况1 int const *a = &b //        2 ...

  8. PID控制器开发笔记之三:抗积分饱和PID控制器的实现

    积分作用的引入是为了消除系统的静差,提高控制精度.但是如果一个系统总是存在统一个方向的偏差,就可能无限累加而进而饱和,极大影响系统性能.抗积分饱和就是用以解决这一问题的方法之一.这一节我们就来实现抗积 ...

  9. 探索一个NSObject对象占用多少内存?

    1 下面写代码测试探索NSObject的本质 Objective-C代码,底层实现其实都是C\C++代码 #import <Foundation/Foundation.h> int mai ...

  10. mongodb 数据库中 的聚合操作