使用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. wchar_t*转换string

    场景 wchar[]转换string 实现代码 #include "stdafx.h" #include <iostream> #include <windows ...

  2. Python3-操作系统发展史

    操作系统发展史 手工操作 —— 穿孔卡片 批处理 —— 磁带存储 多道程序系统 操作系统的作用 手工操作 —— 穿孔卡片 1946年第一台计算机诞生--20世纪50年代中期,计算机工作还在采用手工操作 ...

  3. AMBA总线协议AHB、APB、AXI对比分析【转】

    转自:https://blog.csdn.net/ivy_reny/article/details/56274412 一.AMBA概述    AMBA (Advanced Microcontrolle ...

  4. cosmic_download-AsyncPool待修正

    # !/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/11/16 10:02 AM # @Author : cxa # @File ...

  5. whistle工具全程入门

    接触过前后端开发的同学应该都了解网络请求代理工具fiddler(mac下面常用的是Charles),可以用来拦截分析请求.包装请求.本地调试和移动端代理开发调试等.多多少少,fiddler和Charl ...

  6. javascript动态的改变checkbox的选中状态

    <td> <div class="checkbox"> <label> <input type="checkbox" ...

  7. Docker的离线安装

    由于公司需要离线部署Docker,这里将其步骤记录下来. 目标环境Centos7.2. 由于目标环境为公司内网,首先尝试在https://download.docker.com/linux/cento ...

  8. TX2 开发套件串口

    TX2的底板上有三个串口,位于J21的ttyTHS1,位于J17的ttyTHS2和给蓝牙使用的ttyTHS3. ttyTHS1是控制台串口(serial console),再启动的时候会通过它打印一系 ...

  9. ansible笔记(11):初识ansible playbook(二)

    ansible笔记():初识ansible playbook(二) 有前文作为基础,如下示例是非常容易理解的: --- - hosts: test211 remote_user: root tasks ...

  10. const成员函数和mutable关键字

    一.const成员函数 class MyClass { public: void fun() const { } private: int m_nValue; } const成员函数内不能修改成员变量 ...