String operations

A

Anoop Rajendra

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?

Thanks,
Anoop ///
________________________________________________
The happiest time of a person's life is after his first divorce.
-- J.K. Galbraith
 
S

Steve Holden

Anoop said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,212
Messages
2,571,101
Members
47,697
Latest member
looped_monk

Latest Threads

Top