gpt4 book ai didi

python - Python 中的子进程 : File Name too long

转载 作者:太空狗 更新时间:2023-10-29 17:56:13 27 4
gpt4 key购买 nike

我尝试通过 Python 2.6 中的子进程模块调用 shellscript。

import subprocess

shellFile = open("linksNetCdf.txt", "r")

for row in shellFile:
subprocess.call([str(row)])

我的文件名长度在 400 到 430 个字符之间。调用脚本时出现错误:

File "/usr/lib64/python2.6/subprocess.py", line 444, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1106, in _execute_child
raise child_exception
OSError: [Errno 36] File name too long

linksNetCdf.txt 中的行示例是

./ShellScript 'Title' 'Sometehing else' 'InfoInfo' 'MoreInformation' inputfiile outputfile.txt 3 2

任何想法如何仍然运行脚本?

最佳答案

subprocess.call 可以采用两种方式运行命令 - 可以是您在 shell 中键入的单个字符串,也可以是后跟参数的可执行文件名称列表。

你想要第一个,但正在使用第二个

import subprocess

shellFile = open("linksNetCdf.txt", "r")

for row in shellFile:
subprocess.call(row, shell=True)

通过将您的转换为包含单个字符串的列表,您说的是类似“运行名为echo these were supposed to be arguments的命令没有参数”

关于python - Python 中的子进程 : File Name too long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29747108/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com