473,661 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling GNU/make from a Python Script

Hello,

I need to call GNU/make from within a Python script. This raised some
problems:
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.
2. After searching around, it seems that os.system(..) should be avoided
if there's an alternative. Is there one in this case?

Many Thanks!

Efrat
Oct 30 '06 #1
5 10461
Efrat Regev wrote in news:45******@n ews.bezeqint.ne t in comp.lang.pytho n:
Hello,

I need to call GNU/make from within a Python script. This raised some
problems:
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.
2. After searching around, it seems that os.system(..) should be avoided
if there's an alternative. Is there one in this case?
USe the subprocess module, in particular see

Popen: http://docs.python.org/lib/node529.html

and call: http://docs.python.org/lib/node530.html

you will need to use the "cwd" argument.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Oct 30 '06 #2
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>

Oct 30 '06 #3

Fredrikbuild_di r = "path/to/makefile"

Fredrikcwd = os.getcwd() # get current directory
Fredriktry:
Fredrik os.chdir(build_ dir)
Fredrik os.system("make ")
Fredrikfinally:
Fredrik os.chdir(cwd)

Or even:

os.system("make -C %s" % build_dir)

Skip
Oct 30 '06 #4
sk**@pobox.com wrote:
Fredrikbuild_di r = "path/to/makefile"

Fredrikcwd = os.getcwd() # get current directory
Fredriktry:
Fredrik os.chdir(build_ dir)
Fredrik os.system("make ")
Fredrikfinally:
Fredrik os.chdir(cwd)

Or even:

os.system("make -C %s" % build_dir)
OP specified GNU make, so that works fine, but make sure you're not
going to need to use it with another make before settling on that
alternative. Frederik's works with more versions of make.

Oct 30 '06 #5
>os.system("mak e -C %s" % build_dir)
>OP specified GNU make, so that works fine, but make sure you're not
going to need to use it with another make before settling on that
alternative. Frederik's works with more versions of make.
Understood. That was the only reason I suggested it.

Skip
Oct 30 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2216
by: Raja | last post by:
I have a java class thats trying to call something in python. This works fine when i do a jythonc on the python script. When i call another python script from the __init__ of my called python script, things go bad.i get this message AttributeError: class 'configuration' has no attribute 'configuration' when calling the constructor. This is my python script thats called by the java class testconfig.py =============
22
6306
by: Brad Tilley | last post by:
Is it possible to write a file open, then read program in C and then call the C program from a Python script like this: for root, files, dirs in os.walk(path) for f in files: try: EXECUTE_C_PROGRAM If possible, how much faster would this be over a pure Python solution?
12
7274
by: guy lateur | last post by:
Hi all, I am trying to write some code (macro's, if you like) to glue together our Office applications (mainly Word, Excel and Outlook). We have a lot of different projects going on simultaneously. The idea is to develop a centralized framework (starting point, common interface) for my users to view/control their documents/correspondence, on a per project basis. As an example, I'd like to have a control (button, menu entry) in Outlook...
5
2150
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py" that defines some paths, variables etc. without using Windows environment variables. Various other "hackers" will make additional Python scripts (subroutines) like "gen.py" that utilize variables set by the "main.py" and which "main.py" calls. I can do this with "subprocess" module by setting...
2
1110
by: Jim | last post by:
I have a C++ app which fires up a Python script using C API calls. That script operates the app via Automation calls, like this: from win32com.client import * from mywrapper import * myapp = Application() myapp.Visible = True mydoc = myapp.Documents.Open(...)
5
2566
by: Shuaib | last post by:
Hi! I have a python script which returns an Integer value. How do I call this script from a C programe, and use the result returned? Thanks for your time.
3
2188
by: Kenneth McDonald | last post by:
I know that there's some work out there to let Python make use of Javascript (Spidermonkey) via (I assume) some sort of bridging C/C++ code. Anyone know of efforts to allow the reverse? I'd really like to make use of Python when doing Mozilla DOM programming, and I can never get a clear idea of when PyXPCOM might be available to those of us who don't know the ins and outs of compiling Mozilla, and its XPCOM structures. So if there was an...
3
2072
by: Anthony Smith | last post by:
In my php page I am calling a Python cgi. The problem is that originally the Python script was being called directly and it could access the environment variables that were being set. Now since the php script is being called first it has access to the environment variables, but the Python script does nt. How can I forward the variables or call the Python script in such a way where it can access those variables? These are the type of...
4
6186
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages generated are written to a log file. A project team working in the same company as me here would like to use this loading utility. They write UI applications for Windows using Java. They were able to launch the Python script from within Java by...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8758
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.