Python: subprocess call with shell=False not working

后端 未结 4 1869
孤街浪徒
孤街浪徒 2020-12-01 16:57

I am using Python script to invoke a Java virtual machine. The following command works:

subprocess.call([\"./rvm\"], shell=False)  # works
subprocess.call([\         


        
4条回答
  •  隐瞒了意图╮
    2020-12-01 17:01

    You need to split the commands into separate strings:

    subprocess.call(["./rvm", "xyz"], shell=False)
    

    A string will work when shell=True but you need a list of args when shell=False

    The shlex module is useful more so for more complicated commands and dealing with input but good to learn about:

    import shlex
    
    cmd = "python  foo.py"
    subprocess.call(shlex.split(cmd), shell=False)
    

    shlex tut

提交回复
热议问题