Python3中的
一、subprocess.check_output函数可以执行一条sh命令,并返回命令的输出内容,用法如下:
(1)
output = subprocess.check_output(["python3", "nncp.py"], shell = False)
if (output.find("yes") >= 0):
print("yes")
else:
print("no")
(2)
output = subprocess.check_output(request_cmd, shell=True)
output = str(output ).strip()
二、os.system():
也可以输出命令,但是无法获取到返回值,返回的错误码与linux错误码意义相同
#define EPERM 1 /* Operation not permitted /
#define ENOENT 2 / No such file or directory /
#define ESRCH 3 / No such process /
#define EINTR 4 / Interrupted system call /
#define EIO 5 / I/O error /
#define ENXIO 6 / No such device or address /
#define E2BIG 7 / Argument list too long /
#define ENOEXEC 8 /