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 5 10442
Efrat Regev wrote in news:45******@news.bezeqint.net in comp.lang.python:
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/
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>
Fredrikbuild_dir = "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 sk**@pobox.com wrote:
Fredrikbuild_dir = "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.
>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.
Understood. That was the only reason I suggested it.
Skip This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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:...
|
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...
|
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...
|
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 =...
|
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.
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |