Need help running external program

Rigga rigga at hasnomail.com
Wed Mar 2 17:07:05 EST 2005


Tim Jarman wrote:

> Rigga wrote:
> 
>> Brian van den Broek wrote:
>> 
>>> Rigga said unto the world upon 2005-02-27 15:04:
> 
> (snip stuff about raw strings)
> 
>> Thanks for all your help with this it is appreciated, one further
>> question though, how do I pass a variable to the external program while
>> using the r"""
>> 
>> Thanks
>> 
>> RiGGa
> 
> I'm not sure I understand the question. Say you have:
> 
> parameter = r"my \funky \text"
> 
> then surely you just pass it to your external program using whichever
> method you like, e.g.
> 
> import os
> os.execl("your_external_prog", parameter) # replaces the current process
> 
> or some variant of:
> 
> return_code = os.spawnl(os.P_WAIT, "your_external_prog", parameter)
> 
> or you can build a command line:
> 
> command = "your_external_prog %s" % parameter
> return_code = os.system(command)
> 
> (see docs on the os module for more variations on this theme than you can
> shack a stick at)
> 
> It's just a string, after all.
> 
> 
> 
This is the command I am trying to run:

feed is a list of web addresses

output, input = popen2("wget -q %s -O - | tr '\r' '\n' | tr \' \" | sed -n
's/.*url="\([^"]*\)".*/\1/p'" % feed[counter])

But it does not work, if I escape the string using r""" and hard code in the
web address rather than use %s and feed[counter] it works, my question is
how do I escape the string to get it to work with the %s and feed[counter]

Im new to python as you can tell :-)



More information about the Python-list mailing list