私はどの言語で書かれたアプリケーション(.exe)も持っています。 C + +とPythonからアプリケーションを実行したい。Pythonの子プロセスにある別のアプリケーションとの対話セッション
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
void foo(string s) {
for (int i = 0; i < 3; ++i)
{
cout << "Welcome " << s << " ";
Sleep(2000);
}
}
int main()
{
string s;
cin>> s;
foo(s);
return 0;
}
これが私のために正常に動作します:私はここで次のチュートリアルでサンプルPythonコードの下に使用してhttps://docs.python.org/2/library/subprocess.html
from subprocess import Popen, PIPE
process = Popen([r"C:\Users\...\x64\Debug\Project13.exe"],stdout = PIPE,
stderr=PIPE, stdin = PIPE)
stdout = process.communicate(input = b"Bob")[0]
print(stdout)
C++のコードを単純なアプリケーションを実行することができます。しかし、私はC++アプリケーションで以下のように複数回の入力を読んでいた場合:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
string s;
for (int i = 0; i < 3; ++i)
{
cin >> s;
cout << "Welcome " << s << " ";
Sleep(2000);
}
return 0;
}
をここで私は(process.communicateを使用することはできませんよ)を複数回する子供はすでにそれがreturns.Basically私の時間で終了しているので、連続セッションとしてプログラムとやり取りしたい 私はこの問題をPythonで解決するための提案や他のアプローチが欲しいですか?前もって感謝します。
これは機能しているかどうかを確認してもらえると思われます。ありがとう – flamelite