Python linux export,在Linux上的python中使用’export’进行子进程模块错误?

问题是导出不是实际的命令或文件.它是bash和sh之类的shell的内置命令,所以当你尝试subprocess.Popen时,你会得到一个异常,因为它找不到导出命令.默认情况下,Popen执行一个os.execvp()来生成一个新进程,该进程不允许使用shell内部函数.

你可以做这样的事,虽然你必须改变你对Popen的号召.

您可以指定shell = True以使其使用shell命令.

class subprocess.Popen(args,bufsize = 0,executable = None,stdin = None,stdout = None,stderr = None,preexec_fn = None,close_fds = False,shell = False,cwd = None,env = None,universal_newlines = False,startupinfo = None,creationflags = 0)

On Unix,with shell=True: If args is a string,it specifies the command string to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt. This includes,for example,quoting or backslash escaping filenames with spaces in them. If args is a sequence,the first item specifies the command string,and any additional items will be treated as additional arguments to the shell itself. That is to say,Popen does the equivalent of:

Popen(['/bin/sh','-c',args[0],args[1],...])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值