General

외부 프로그램 실행

by pjk posted Feb 10, 2015
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

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")