Tharanga Abeyseela
Tharanga Abeyseela

Reputation: 3483

passing Python variable to triple quoted curl command

SIZ=100

imap_cmd="""
curl -s -X GET --insecure -u xxx https://xxxxx/_search?pretty=true -d '{
"from":0,
"size":%SIZ,
"query":{ "match_all": {} },
"_source":["userEmail"]
}' | grep -i userEmail|awk {'print $3'} | cut -d ',' -f1
"""
def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = (p.communicate()[0])

    return output

I'm trying to pass the SIZ (python) variable to the curl command, but it is not interpreting the value when i execute the command. what I'm missing here

Upvotes: 0

Views: 926

Answers (1)

Jason
Jason

Reputation: 2304

It looks like you're trying to use the % formatter in this line,

"size":%SIZ,

try

imap_cmd="""
curl -s -X GET --insecure -u xxx https://xxxxx/_search?pretty=true -d '{
"from":0,
"size":%d,
"query":{ "match_all": {} },
"_source":["userEmail"]
}' | grep -i userEmail|awk {'print $3'} | cut -d ',' -f1
""" % SIZ

Here is more info on formatting strings.

Upvotes: 1

Related Questions