한국어
파이썬
 

General 외부 프로그램 실행

pjk 2015.02.10 22:53 조회 수 : 15361

the following "example.exe" C++ program:

 

int main(int argc, char *argv[])
{
    int number = 0;
    do {
        scanf("%d", &number);
        for(int x=1; x<=number; x++) {
                printf("%d n", x);
        }
    } while (number >= 1);
    
    return EXIT_SUCCESS;
}

 

Code:

 

import subprocess, os

PIPE = subprocess.PIPE
p = subprocess.Popen("example.exe", stdin=PIPE, stdout=PIPE)

p.stdin.write("10")
p.stdin.flush()
print p.stdout.read() #Deadlock

print "End of Execution"
os.system("PAUSE")