0

I have a url that contains bunch of ampersands. I also have a cmd given below

cmd = 'wget --verbose --auth-no-challenge --no-check-certificate -O res'

When I run the command using subprocess my url options after the first ampersand are not included in the actual query.

>>> p = subprocess.Popen(cmd + " " + url , shell=True)

What can I do to make sure that the entire url is passed ?

2 Answers 2

2

I've run into similar issues with trying to figure out how to format the command for Popen. Now I almost always use shlex.split() to do it for me.

Example from python.org:

>>> import shlex, subprocess
>>> command_line = raw_input()
/bin/vikings -input eggs.txt -output "spam spam.txt" -cmd "echo '$MONEY'"
>>> args = shlex.split(command_line)
>>> print args
['/bin/vikings', '-input', 'eggs.txt', '-output', 'spam spam.txt', '-cmd', "echo '$MONEY'"]
>>> p = subprocess.Popen(args) # Success!

So for this particular example, you might have something like

>>> import shlex, subprocess
>>> url = 'http://www.example.com/somepage.html?foo=spam&bar=eggs&baz=ni'
>>> cmd = 'wget --verbose --auth-no-challenge --no-check-certificate -O res ' + url
>>> args = shlex.split(cmd)
>>> p = subprocess.Popen(args)
>>> --2013-12-13 13:36:11--  http://www.example.com/somepage.html?foo=spam&bar=eggs&baz=ni
Sign up to request clarification or add additional context in comments.

Comments

1

try quoting the url using single quotes:

 url = "'what&ever&address'"

Comments

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.