Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python subprocess.Popen及其参数的最大字符长度_Python_Subprocess - Fatal编程技术网

Python subprocess.Popen及其参数的最大字符长度

Python subprocess.Popen及其参数的最大字符长度,python,subprocess,Python,Subprocess,我的python代码中有一行相当简单的代码: Popen(["t2x",cfile],env=denv,stdout=h) 这一行有一个bug,我最终意识到输入文件cfile的名称太长了。因此,我得到了一个分割错误。我知道这一定是问题所在,因为我可以用较短的cfile路径运行相同的代码,并且可以正常工作 问题是名称cfile可以有多长?如果我还有cwd=dir,我是否对dir的字符数也有限制?我们能绕过这些限制吗 下面是出现问题的代码和错误消息: import os import subpro

我的python代码中有一行相当简单的代码:

Popen(["t2x",cfile],env=denv,stdout=h)
这一行有一个bug,我最终意识到输入文件
cfile
的名称太长了。因此,我得到了一个分割错误。我知道这一定是问题所在,因为我可以用较短的
cfile
路径运行相同的代码,并且可以正常工作

问题是名称
cfile
可以有多长?如果我还有
cwd=dir
,我是否对
dir
的字符数也有限制?我们能绕过这些限制吗

下面是出现问题的代码和错误消息:

import os
import subprocess

dir="/scratch" 

cfile="/home/user/simulation_data/2017_systemBC_efield/BCline01/bssecorrection/bsseE=0+H2(1)/scan_0000/bsse/coord"

xyz="temp.xyz"

denv=dict(os.environ)

with open(xyz,"w") as h:
    p1=subprocess.Popen(["t2x",coordfile],env=denv,cwd=dir,stdout=h)
    p1.wait()
错误消息:

Taking coordinates from file:  /home/user/simulation_data/2017_systemBC_efield/BCline01/bssecorrection/bsseE=0+H2(1)/scan_0000/bsse/coord
No structure optimization data found.
Only coord data will be converted.
Segmentation fault (core dumped)
Segmentation fault (core dumped)
Segmentation fault (core dumped)
Segmentation fault (core dumped)
Segmentation fault (core dumped)

那要看情况了。就你而言,不是波本。至少在Python2.7中,您可以测试将命令从“t2x”改为“ls”,您将看到它将毫无问题地执行。这使我们得出结论,t2x正在为给定参数分配一个非常小的缓冲区,并且可能还允许缓冲流,这是根据您得到seg的事实进行的猜测-faults@DavidBern我觉得有点傻。事实上,t2x脚本就是问题所在。不幸的是,我无法修复它。你有访问源代码的权限吗?@DavidBern我有,但我现在不会修改它,因为这需要一点时间。我会在某个时候着手解决它,或者让开发人员在下一个版本中修复它。这听起来似乎是一个需要修复的简单问题。