Subprocess in Python: File Name too long

前端 未结 2 665
臣服心动
臣服心动 2021-02-19 20:36

I try to call a shellscript via the subprocess module in Python 2.6.

import subprocess

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

for row in shellFile:
    s         


        
2条回答
  •  时光说笑
    2021-02-19 21:16

    subprocess.call can take the command to run in two ways - either a single string like you'd type into a shell, or a list of the executable name followed by the arguments.

    You want the first, but were using the second

    import subprocess
    
    shellFile = open("linksNetCdf.txt", "r")
    
    for row in shellFile:
        subprocess.call(row, shell=True)
    

    By converting your row into a list containing a single string, you're saying something like "Run the command named echo these were supposed to be arguments with no arguments"

提交回复
热议问题