Curly Braces in python Popen

前端 未结 3 507
再見小時候
再見小時候 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: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')
    

提交回复
热议问题