Re: running programs from within python

M

M.N.A.Smadi

M.N.A.Smadi said:
hi;
in general: how can i pass a string containing a concatenated sequcne
of command line arguments to a unix system CLI?

my specific problem:
i have an executable that is called xyz (written in C if that matters)
that i cannot modify, which prints it is text output to the screen and
takes an input as t.txt.
on a unix terminal, i do the ./xyz t.txt > tmp.txt
so that the tmp.txt will contain the output of the xyz executable

i tried the following but it did not work

import os
os.execl("./xyz","t.txt > tmp.txt") #the thing just hangs there
i aslo tried
os.execl("./xyz","t.txt") # but it does not output anything to the
screen either, hangs there too

any suggestions?

thanks
m.smadi

i guess i will answer myself:
import os
os.system(string)

!!
 
M

M.N.A.Smadi

am getting an error in the script as follows:

NameError: global name 'os' is not defined

however i dont get the same error when running from the python CLI. (and
yes i am importing the os module)

is this a bug in python 2.3 (the one am currently using)
thanks
m.smadi
 
S

Steven Bethard

M.N.A.Smadi said:
am getting an error in the script as follows:

NameError: global name 'os' is not defined

however i dont get the same error when running from the python CLI. (and
yes i am importing the os module)

Can you give the full exception message (i.e. copy-paste it from the
output)?

STeVe
 
M

M.N.A.Smadi

this is the full error


Traceback (most recent call last):
File "./plugin.py", line 60, in ?
main()
File "./plugin.py", line 40, in main
os.system("/root/tmp/bibutils_3.14/isi2xml " + isi_file + " >
tmp_isi_xml.xml")
NameError: global name 'os' is not defined

smadi
 
J

James Stroud

You should

import os

this is the full error


Traceback (most recent call last):
File "./plugin.py", line 60, in ?
main()
File "./plugin.py", line 40, in main
os.system("/root/tmp/bibutils_3.14/isi2xml " + isi_file + " >
tmp_isi_xml.xml")
NameError: global name 'os' is not defined

smadi
 
S

Steven Bethard

M.N.A.Smadi said:
> am getting an error in the script as follows:
>
> NameError: global name 'os' is not defined
>
> however i dont get the same error when running from the python CLI.
> (and yes i am importing the os module)
> Steven Bethard wrote:
> Can you give the full exception message (i.e. copy-paste it from the
> output)?

M.N.A.Smadi top-posted:
this is the full error

Traceback (most recent call last):
File "./plugin.py", line 60, in ?
main()
File "./plugin.py", line 40, in main
os.system("/root/tmp/bibutils_3.14/isi2xml " + isi_file + " >
tmp_isi_xml.xml")
NameError: global name 'os' is not defined

Hmmm... I don't see how you'd get this if you're really importing the
os module (as you say above). Are you sure that you have 'import os' at
the top of plugin.py? You don't have any conditional wrapped around it
do you?

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top