Hackaholic Hackaholic - 5 months ago 12x
Python Question

subprocess ls examples/* no fuch file or directory

>>> import subprocess
>>> child = subprocess.Popen(["ls", "examples/*"], stdout=subprocess.PIPE)
>>> ls: examples/*: No such file or directory

But from terminal it works

Beagle:kumarshubham$ ls examples/*
examples/convert_greyscale.py examples/feat_det_harris_corner.py examples/read_display_image.py
examples/example_set_roi.py examples/manipulate_img_matplotlib.py examples/remove_matplotlib_cache.py

Can one guide me where i am going wrong?


This is because of (*) wild card usage. You need to supply shell=True to execute the command through shell interpreter

>>> import subprocess
>>> child = subprocess.Popen(["ls", "examples/*"], stdout=subprocess.PIPE, shell=True)