String operations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anoop Rajendra

    #1

    String operations

    Hi. I'm trying to resolve an issue with strings.

    The command(inclusi ve of the back-slashes)

    condor_q -l -constraint "ProjectId==\"a noopr_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('cond or_q -l -constraint "ProjectId==\\\ "anoopr_samadam s.fnal.gov_1619 03_30209\\\""')

    But, I'd rather use the os.exec functions to get the output. But

    os.execvp("cond or_q",["condor_q", "-l","-constraint",'"P rojectId==\\\"a noopr_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


  • Steve Holden

    #2
    Re: String operations

    Anoop Rajendra wrote:
    [color=blue]
    > Hi. I'm trying to resolve an issue with strings.
    >
    > The command(inclusi ve of the back-slashes)
    >
    > condor_q -l -constraint "ProjectId==\"a noopr_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('cond or_q -l -constraint "ProjectId==\\\ "anoopr_samadam s.fnal.gov_1619 03_30209\\\""')
    >
    > But, I'd rather use the os.exec functions to get the output. But
    >
    > os.execvp("cond or_q",["condor_q", "-l","-constraint",'"P rojectId==\\\"a noopr_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?
    >[/color]
    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("cond or_q",["condor_q", "-l","-constraint",'Pr ojectId=="anoop r_samadams.fnal .gov_161903_302 09"'])

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

    os.execvp("cond or_q",["condor_q", "-l","-constraint",'Pr ojectId==anoopr _samadams.fnal. gov_161903_3020 9'])

    or

    os.execvp("cond or_q",["condor_q", "-l","-constraint","Pr ojectId==anoopr _samadams.fnal. gov_161903_3020 9"])

    regards
    Steve
    --


    Holden Web LLC +1 800 494 3119

    Comment

    Working...