Answer the question
In order to leave comments, you need to log in
Why does Popen.wait() cause the subprocess to work incorrectly?
I'm writing a python program that needs to compile a .cpp file into an .exe and run it.
There is a MinGW compiler in the project folder, with the help of which I am just going to compile the program. When I run it with the Popen command in python (I used both the subprocess library and psutil) everything works fine.
proc = psutil.Popen('"./MinGW/compile_code_1.cmd"', shell=True, stdout=subprocess.PIPE)
c:/users/cergm/desktop/unit tests/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function ` main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `[email protected]'
collect2: ld returned 1 exit status
@echo off
set PATH=%~dp0bin;%PATH%
title MinGW Portable Command Prompt
cd /d "%~dp0"
g++ ../solutions/code_1/main.cpp -o ../solutions/code_1/main
exit
#include <iostream>
#include <cstdio>
using namespace std;
int main(int narg, char*args[])
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int a, b;
cin >> a >> b;
cout << a + b;
}
Answer the question
In order to leave comments, you need to log in
1. Your windows-gui application is compiling. Try explicitly looking towards the -m option for g++ and adding the correct value to your cmd script. There are no vents at hand, I can’t say more.
2. This function kind of runs your command with the specified parameters and waits for completion, doesn't it? (This is about waiting for completion)
The problem is solved, it lies in the fact that before starting g ++ I was writing to the main.cpp
file And the file simply did not update. To fix this you need to addcode_1_file.flush()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question