1

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!

1 Answer 1

1

Try changing call(cmd) to call(cmd, shell=True)

Sign up to request clarification or add additional context in comments.

2 Comments

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!
It is probably your exit-code. If you want to capture the output instead of the exitcode, you can use subprocess.check_output()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.