Calling GNU/make from a Python Script

Fredrik Lundh fredrik at pythonware.com
Mon Oct 30 10:05:03 EST 2006


Efrat Regev wrote:

> 1. The script is not in the directory of the makefile, and changing the 
> locations of either is not an option. Consequently, the makefile fails, 
> since it can't find the targets/dependencies.

build_dir = "path/to/makefile"

cwd = os.getcwd() # get current directory
try:
     os.chdir(build_dir)
     os.system("make")
finally:
     os.chdir(cwd)

> 2. After searching around, it seems that os.system(..) should be avoided 
>   if there's an alternative.   Is there one in this case?

"make" is not an operating system service, no.

</F>




More information about the Python-list mailing list