使用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. Python学习笔记-解释器和中文编码

    第一行 #!/usr/bin/env python 目的是指出用什么可执行程序去运行代码. 有两种写法 1.#!/usr/bin/python 调用/usr/bin下的python解释器,去运行代码. ...

  2. P1456 Monkey King

    题目地址:P1456 Monkey King 一道挺模板的左偏树题 不会左偏树?看论文打模板,完了之后再回来吧 然后你发现看完论文打完模板之后就可以A掉这道题不用回来了 细节见代码 #include ...

  3. 手写代码 - java.lang.String/StringBuilder 相关

    语言:Java 9-截取某个区间的string /** * Returns a string that is a substring of this string. The * substring b ...

  4. nginx+supervisor+gunicorn+flask

    一. 更新系统 #yum -y install epel-release #yum clean all && yum makecache #yum -y update 二.安装pyth ...

  5. Contains Duplicate I & III

    Contains Duplicate I Given an array of integers, find if the array contains any duplicates. Your fun ...

  6. CentOS 6与7对比【转】

    片段1:时间同步 CentOS 6 逐步: ntpd或ntpdate 直接: ntpdate -b(通常加到crontab) CentOS 7 方法1: systemctl start chronyd ...

  7. jQuery插件开发jQuery.extend(object)和jQuery.fn.extend()

    jQuery插件开发 知识1:用JQuery写插件时,最核心的方法有如下两个: $.extend(object) 可以理解为JQuery 添加一个静态方法. $.fn.extend(object) 可 ...

  8. codeforces 955F Cowmpany Cowmpensation 树上DP+多项式插值

    给一个树,每个点的权值为正整数,且不能超过自己的父节点,根节点的最高权值不超过D 问一共有多少种分配工资的方式? 题解: A immediate simple observation is that ...

  9. python 基础 three day

    本节主要内容: 一. python基本数据类型有哪些? 1. int  ==>  整数.主要用来进行数学计算. 2. str ==> 字符串,可以保存少量数据并进行相应的操作 3. boo ...

  10. 【原创】Linux基础之opensuse15

    装机 装机之后执行 sudo zypper ar -fc https://mirrors.aliyun.com/opensuse/distribution/leap/15.0/repo/oss ope ...