String operations

Steve Holden steve at holdenweb.com
Wed Dec 1 23:34:54 CET 2004


Anoop Rajendra wrote:

> Hi. I'm trying to resolve an issue with strings.
> 
> The command(inclusive of the back-slashes)
> 
> condor_q -l -constraint "ProjectId==\"anoopr_samadams.fnal.gov_161903_30209\""
> 
> is the only way the command returns the right result. 
> I'm trying to run this command from inside a python program.
> The way I can get it work is by: 
> 
> os.system('condor_q -l -constraint "ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""')
> 
> But, I'd rather use the os.exec functions to get the output. But 
> 
> os.execvp("condor_q",["condor_q","-l","-constraint",'"ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""'])
> 
> doesnt work. Its definately a problem with one of the million
> backslashes and quotes present, but I'm not able to figure it out.
> What am I doing wrong?
> 
I believe that you don't need to escape the quotes inside the argument 
strings when you call os.execvp(), because there's no shell interpreting 
the arguments. So, in theory, what you appear to need would be

os.execvp("condor_q",["condor_q","-l","-constraint",'ProjectId=="anoopr_samadams.fnal.gov_161903_30209"'])

or even, since I don't see the need for the quotes in the first place,

os.execvp("condor_q",["condor_q","-l","-constraint",'ProjectId==anoopr_samadams.fnal.gov_161903_30209'])

or

os.execvp("condor_q",["condor_q","-l","-constraint","ProjectId==anoopr_samadams.fnal.gov_161903_30209"])

regards
  Steve
-- 
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119



More information about the Python-list mailing list