Results of executing hyperlink in script

Jean-Paul Calderone exarkun at divmod.com
Wed Jan 28 18:29:08 EST 2009


On Wed, 28 Jan 2009 23:14:59 +0000, MRAB <google at mrabarnett.plus.com> wrote:
>Muddy Coder wrote:
>>Hi Folks,
>>
>>My previous post got a many helps from the people, and I tested what
>>they suggested. Since this topic maybe needed in future, so I drop
>>these lines below to help the future programmers. The methods worked
>>as below:
>>
>>1. This method was suggested by Cameron Laird:
>>
>>       os.system("start %s" % URL)
>>
>>It works. But, if the URL contains character &, it will fail. For
>>example, if URL has only one field, such as: 
>>http://www.mydomain.com/ascript.cgi?user=muddy
>>this method works well. But, if there more than one field need to be
>>input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo,
>>the field password failed to reach server, and the CGI script
>>complained.
>You could put quotes around the URL:
>
>os.startfile('"%s"' % URL)
>
>or:
>
>os.system('start "%s"' % URL)
>
>if "&" has a special meaning to the command-line.

What if the URL has a " in it?  Worse, what if the URL is:

    " & rm -rf ~

os.system is a pretty bad thing to use.  Fortunately, the suggestion to
use urllib was a much better one, and you can't use os.system here anyway
since the poster is interested in getting the contents of the page at the
URL.

Jean-Paul



More information about the Python-list mailing list