Executing python scripts with subprocess.call using shebang

前端 未结 2 791
孤街浪徒
孤街浪徒 2021-01-21 00:57

I\'m writing a (somewhat) modular application in Python 3 and I\'d like to run arbitrary programs from it, said program being specified at runtime and not necessarily a python s

相关标签:
2条回答
  • 2021-01-21 01:22

    Try

    subprocess.call(['spam.py', "-i", eggs, "-o", ham])
    
    0 讨论(0)
  • 2021-01-21 01:24

    You need to use shell=True, and you need your array to be turned into a command string, like this:

    subprocess.call(' '.join([spam, "-i", eggs, "-o", ham]), shell=True)
    

    This will invoke the shell instead of the direct command, and the shell should be able to handle the shebang.

    0 讨论(0)
提交回复
热议问题