Curly Braces in python Popen

前端 未结 3 506
再見小時候
再見小時候 2020-12-17 03:59

Running subprocess won\'t handle curly braces correctly

# Python 2.7.4

import subprocess
subprocess.Popen(\'ls src/*.cpp\',shell=True): 
src/tonemap.cpp src         


        
相关标签:
3条回答
  • 2020-12-17 04:09

    The other machine uses a different shell that doesn't handle that syntax.

    0 讨论(0)
  • 2020-12-17 04:17

    In your case, Popen executed correctly, error is reported from ls. It should give same error when you execute the command:

    ls src/{t,p}*.cpp
    

    in terminal.

    0 讨论(0)
  • 2020-12-17 04:26

    shell=True runs /bin/sh that doesn't support this syntax. Specify bash explicitly:

    from subprocess import check_call
    
    check_call('ls src/{t,p}*.cpp', shell=True, executable='/bin/bash')
    
    0 讨论(0)
提交回复
热议问题