Reputation: 25
I tried to build project by make in python on macOS Mojave, but I get this output:
If there are problems, cd to the src directory and run make there
cd src && /Library/Developer/CommandLineTools/usr/bin/make first
rm -f auto/config.status auto/config.cache config.log auto/config.log
rm -f auto/config.h auto/link.log auto/link.sed auto/config.mk
touch auto/config.h
cp config.mk.dist auto/config.
Process finished with exit code 0
But if I try start make from terminal all works fine. Here my python code:
make_command = "make"
make_proc = subprocess.Popen(make_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=args[1])
args[1] – path to folder with project, its correct ("/Users/kirill/.vim_updater")
Can anyone help me solve this problem?
Upvotes: 1
Views: 2862
Reputation: 5329
As you mentioned in your question Process finished with exit code 0
. It means your make
command was success. You can try the following improved code part.
Code:
import subprocess
import sys
make_command = ["make"]
make_proc = subprocess.Popen(make_command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=sys.argv[1])
stdout, stderr = make_proc.communicate()
print("stdout: {}".format(stdout))
print("stderr: {}".format(stderr))
print("Return code: {}".format(make_proc.returncode))
Output: (If there is no Makefile
in the specific folder. You can see the return code is not zero because of missing Makefile
(error))
>>> python3 test.py .
stdout: b'make: *** No targets specified and no makefile found. Stop.\n'
stderr: None
Return code: 2
And if I create a Makefile
in my .
(root) folder with the following content.
Makefile:
FOO = Hello World
all:
@echo $(FOO)
@echo $(value FOO)
Output: (The Makefile
exists in the specific folder and the content of it is correct so the make
was success and the return code is zero (You have the same situation based on your question).)
>>> python3 test.py .
stdout: b'Hello World\nHello World\n'
stderr: None
Return code: 0
Upvotes: 1
Reputation: 5630
I'm a newbie and still don't have enough reputatio to comment.
So please feel free to try this out and tell me and so that I can delete this 'answer'
Use subprocess.call() instead of subprocess.Popen() you also want to check the return code.
I think you want to wait for the result.
For testing you might also try to use the absolute path of the make command.
Upvotes: 0