I am trying to download the content of a web page to a text file, and hash the url to generate unique file names.. Something like:
$ echo -n "http://www.hussam.us" | md5sum
de8b64952e61cc4c6a38df2d17bb8e0d -
Downloading the content of a web page is not my problem; it is generating the file names by hashing. I am trying this code in python terminal, but it is generating this error as if the module is not imported or installed, but it actually is. Simple commands like "ls" work fine.
>>> import subprocess
>>> cmd = 'echo -n "http://www.hussam.us" | md5sum'
>>> call(cmd)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Thanks!
asked Feb 20, 2017 at 11:50
Hussam Hallak
3135 silver badges22 bronze badges
1 Answer 1
Try changing call(cmd) to call(cmd, shell=True)
answered Feb 20, 2017 at 11:52
J. Meijers
9898 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Hussam Hallak
I did and it worked, but had to call it like this >>> subprocess.call(cmd, shell=True) de8b64952e61cc4c6a38df2d17bb8e0d - 0 Do you have any idea where the zero came from? Thanks a bunch!
J. Meijers
It is probably your exit-code. If you want to capture the output instead of the exitcode, you can use subprocess.check_output()
lang-py