I experimented with Python with C # and I don't know how to execute a Python script and write It commands / data. I watched this link: " https://code.msdn.microsoft.com/windowsdesktop/C-and-Python-interprocess-171378ee "
But just show how to read the output of a Python script, and not how to write something after opening / executing a script.
For example, I want to open a python script (from C Sharp) and send it some data from C # to the raw_input () function.
Could you help me? Links, examples, all are welcome ... I'm lost now.
PS: I do not want to use ironpython
C # Example:
private void button1_Click(object sender, EventArgs e)
{
string python = @"C:\Python27\python.exe";;
string myPythonApp = "myscript/test01.py";
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
myProcessStartInfo.UseShellExecute = false
myProcessStartInfo.CreateNoWindow = true
myProcessStartInfo.RedirectStandardOutput = true
myProcessStartInfo.RedirectStandardInput = true;
myProcessStartInfo.Arguments = myPythonApp;
Process myProcessW = new Process();
Process myProcessR = new Process();
myProcessW.StartInfo = myProcessStartInfo;
myProcessR.StartInfo = myProcessStartInfo;
myProcessW.Start();
myProcessR.Start();
StreamWriter myStreamWriter = myProcessW.StandardInput;
string inputText;
inputText = textBox1.Text;
myStreamWriter.WriteLine(inputText);
myProcessW.WaitForExit();
myProcessW.Close();
StreamReader myStreamReader = myProcessR.StandardOutput;
MessageBox.Show("01");
string myString = myStreamReader.ReadLine();
MessageBox.Show("02");
label1.Text = myString;
myProcessR.WaitForExit();
myProcessR.Close();
}
Python example (myscript / test01.py):
aaa = raw_input("> ")
print "Ok, you say:",aaa
: , "myProcessStartInfo.RedirectStandardInput = false", "RedirectStandardOutput" , ...