Hackaholic Hackaholic - 2 years ago 86
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?

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download