python shell中文_Python Shell Wrapp

首先,为什么要用python处理I/O?只需让子进程的stdout和stderr与python的stdout和stderr放在同一个地方。第二,您可以直接从python检索资源,而不是实际使用time命令。试试这样的方法:#! /usr/bin/python

import os

import resource

import sys

import time

cmd = ' '.join(sys.argv[1:])

stime = time.time()

os.system(cmd) # fire off the command

etime = time.time()

# now get the resource utilization

r = resource.getrusage(resource.RUSAGE_CHILDREN)

user_time = r.ru_utime

sys_time = r.ru_stime

# resource doesn't know "clock" time, so we'll just figure that ourselves

real_time = etime - stime

print "real\t" + str(real_time)

print "user\t" + str(user_time)

print "sys\t" + str(sys_time)

它以秒为单位打印时间。如果您真的希望它们看起来像time命令,可以相应地格式化它们。在

回答你问题的第二部分,实际上有不同的“时间”命令。当您将其作为python的子级运行时,将得到/usr/bin/time的输出。当您手动运行它时,您将获得shell的内置版本time。尝试在shell提示符处键入“type-a time”。另外,试着像这样运行您的测试程序:“/usr/bin/time/测试.py“你应该看看第二种形式。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值