Python subprocess argument with equal sign and space

后端 未结 2 1211
有刺的猬
有刺的猬 2021-01-05 09:08

I am trying to run a command with subprocess.check_output without using shell=True keyword argument. My command is this:

command --         


        
2条回答
  •  不思量自难忘°
    2021-01-05 09:20

    Adding to @Mark's answer, I specifically needed quotes to be passed to the program as well as quotes to surround the parameter. Basically this was what I needed:

    make PAYOFF="\"{{0,1,-1},{-1,0,1},{1,-1,0}}\""
    

    Python doesn't add the extra set of quotes to the very left and very right, so adding a space in front of the equals sign did the trick.

    Calling the list2cmdline functions as follows:

    subprocess.list2cmdline(['make', 'PAYOFF ="{{0,1,-1},{-1,0,1},{1,-1,0}}"'])
    

    would produce this result:

    make "PAYOFF =\"{{0,1,-1},{-1,0,1},{1,-1,0}}\""
    

提交回复
热议问题