python getostime_python超时使用os.system

import subprocess

# Simple command

subprocess.call('ls -l', shell=True)

$ python replace_os_system.py

total 16

-rw-r--r-- 1 root8085 root8085 0 Jul 1 13:27 __init__.py

-rw-r--r-- 1 root8085 root8085 1316 Jul 1 13:27 replace_os_system.py

-rw-r--r-- 1 root8085 root8085 1167 Jul 1 13:27 replace_os_system.py~

# run cmd

import subprocess

l = subprocess.call(['cmd'])

额外例如: 进行系统调用三种不同的方法: #! /usr/bin/env python

import subprocess

# Use a sequence of args

return_code = subprocess.call(["echo", "hello sequence"])

# Set shell=true so we can use a simple string for the command

return_code = subprocess.call("echo hello string", shell=True)

# subprocess.call() is equivalent to using subprocess.Popen() and wait()

proc = subprocess.Popen("echo hello popen", shell=True)

return_code = proc.wait() # wait for process to finish so we can get the return code

控制标准错误和ST dout: #! /usr/bin/env python

import subprocess

# Put stderr and stdout into pipes

proc = subprocess.Popen("echo hello stdout; echo hello stderr >&2", \

shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

return_code = proc.wait()

# Read from pipes

for line in proc.stdout:

print("stdout: " + line.rstrip())

for line in proc.stderr:

print("stderr: " + line.rstrip())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值