subprocess.Popen () не перенаправляет вывод в файл - PullRequest
0 голосов
/ 01 мая 2018

Check.cpp

int main(int argc, char** argv)
{
    string file = "";
    ifstream inFile;
    int x;
    file = argv[1];
    inFile.open(file.c_str());
    while (inFile >> x)
        cout << x << endl;
    return 0;
}

Print.py

from __future__ import with_statement
from shutil import copy
import subprocess
import filecmp
import sys

count = 0
f = open ("filename.txt","r")
file1 = open ("file1.txt","w") 
file2 = open ("file2.txt","w")
file3 = open("out1.txt","w")
file4 = open("out2.txt","w")

for line in range(1,2):
    firstline = f.readline()
    file1.write(firstline)
    subprocess.Popen(["./a.out","file1.txt"],stdout=file3)
    file2.write(firstline)
    subprocess.Popen(["./a.out","file2.txt"],stdout=file4)
    if (filecmp.cmp('out1.txt', 'out2.txt') == True):
        count = count + 1

print count

Введите:

filename.txt:
    123 
    234
    456

Выход:

file1.txt:
    123

file2.txt:
    123

out1.txt:
    Expected Output - 123. But no output is returned

out2.txt
    Expected Output - 123. But no output is returned

Я пытаюсь запустить простую программу на C ++ через скрипт Python. Я попытался subprocess.Popen (), subprocess.call (), subprocess.check_output (). Но никто из них не перенаправляет вывод командной строки в файл.

...