executing a command

Tiago Stürmer Daitx tdaitx at gmail.com
Sat Jun 4 21:10:13 EDT 2005


Hello,

When you use one of the os.exec*p fnnctions python looks for the specified 
file in the directories refered by os.environ['PATH']. If and _only_ if your 
os.enviroment['PATH'] isn't set then it looks in os.defpath - you can check 
this at http://www.python.org/doc/current/lib/os-path.html#l2h-1557

So, my advice is that you first try printing your os.environ['PATH']
to check wheter it includes the program that you are calling or not (and 
then you will have to include it). In the case that it isn't set, then check 
os.defpath.

Also, when you use one of the functions os.exec that requires a path 
variable to be passed (ie. the ones that doesn't have 'p' in their names) 
the path can be relative or absolute, but it must include the file name (and 
not only the dir where the file is).

And for each one of these os.exec* functions the first argument will always 
be used as the program "name" (argv[0]), so unless you a reason to do 
otherwise, pass the same name as the file that you are calling.


Regards,
Tiago S Daitx

On 6/4/05, andrea valle <marta_andrea at tele2.it> wrote:
> Hi to all,
> I need to run a program from inside python (substantially, algorithmic
> batch processing).
> I'm on mac osx 10.3.8 with python 2.3 framework and macpython.
> 
> Trying to use exec*, I checked references, Brueck & Tanner, and then
> grab this code from effbot:
> 
> >>> program = "python"
> >>> def run(program, *args):
> os.execvp(program, (program,) + args)
> print "ok"
> 
> >>> run("python", "/Users/apple/Desktop/prova.py")
> 
> Traceback (most recent call last):
> File "<pyshell#50>", line 1, in -toplevel-
> run("python", "/Users/apple/Desktop/prova.py")
> File "<pyshell#49>", line 2, in run
> os.execvp(program, (program,) + args)
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/os.py", line 336, in execvp
> _execvpe(file, args)
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/os.py", line 374, in _execvpe
> func(fullname, *argrest)
> OSError: [Errno 45] Operation not supported
> 
> This OSError seems to be consistend with all exec family. What does it
> mean and how to use exec?
> 
> I also tried with. os.system. It works if I invoke python, but it fails
> (in a way I don't know) when I invoke other programs.
> 
> For example:
> command = "python /Users/apple/Desktop/test.py"
> >>> os.system(command)
> 0
> (test.py write a string in a file. It works)
> 
> But with lilypond or with latex I have no output (and in fact it
> doesn't give 0 as result):
> 
> >>> command = "lilypond /Users/apple/Desktop/test.ly"
> >>> os.system(command)
> 32512
> >>> command = "latex /Users/apple/Desktop/test.tex"
> >>> os.system(command)
> 32512
> 
> Any help is much appreciated
> 
> Thanks a lot
> 
> -a-
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050604/c2b9de38/attachment.html>


More information about the Python-list mailing list