Created
February 14, 2015 23:45
-
-
Save jesyspa/104ba5e58b7c9e31b1d8 to your computer and use it in GitHub Desktop.
Example of pipes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() { | |
std::cerr << "[C++] Launched" << std::endl; | |
int total = 0; | |
int tmp; | |
while (std::cin >> tmp) { | |
std::cerr << "[C++] Read " << tmp << std::endl; | |
total += tmp; | |
} | |
std::cout << total << std::endl; | |
std::cerr << "[C++] Done" << std::endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import sys | |
print "[Python] Opened file" | |
proc = subprocess.Popen(["./test_program"], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr=sys.stderr) | |
for i in range(5): | |
proc.stdin.write(str(i) + '\n') | |
proc.stdin.close() | |
print "[Python] Done writing!" | |
for line in iter(proc.stdout.readline, ''): | |
print '[Python] Got:', repr(line) | |
print "[Python] Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment