[Tutor] not invoking the shell from python

Alan G alan.gauld at freenet.co.uk
Tue Jun 21 18:58:46 CEST 2005


> input but the shell still expands out certain characters. I noticed
> with python2.4. How do I bypass the shell and hand arguments
directly
> to the program?

The first thing I'd do is create the command string before passing
it to popen - that way we can debug easier by seeing exactly what
is being passed through!

> The problematic line in question looks like this:

cmd = '''rt create -t ticket set requestor='%s' owner='%s'
queue='%s' subject="%s" text="%s" status='%s' ''' %
(data['requestor'],
data['owner'],
data['queue'],
re.sub(r'\"',r'\\"',data['subject']),
re.sub(r'\"',r'\\"',data['body']),
data['status'])
# your code was missing the closing parens above but I assume
# that was just a posting error?

print cmd   # for debug only
os.popen(cmd)

See if the line you are producing is what you think it should be.
Try typing it in at the shell and see if you get the same effect?

Without knowing the details of your data its hard to say much more.

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list