How to send data to Python script from C#
<p>i have been experimented with Python from C# and i do not know how to execute a Python script and write It commands/data. I have been looking this link: "<a href="https://code.msdn.microsoft.com/windowsdesktop/C-and-Python-interprocess-171378ee" rel="nofollow">https://code.msdn.microsoft.com/windowsdesktop/C-and-Python-interprocess-171378ee</a>"</p>

<p>But only show how to read Python script output, not how to write something once the script is open/execute.</p>

<p>For example, i want to open a python script (from C Sharp) and send it some data from C # to a raw_input() funciÃ³n. </p>

<p>Can you help me? Links, examples, all is welcome... I am lost now.</p>

<p>PS: i dont want to use ironpython</p>

<p>C# Example:</p>

<pre><code>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;

            //&lt;&gt;//---------------ISSUE?--------------------------------
            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); // &lt;--OK!

            myProcessW.WaitForExit();
            myProcessW.Close();

            // 
            StreamReader myStreamReader = myProcessR.StandardOutput;
            MessageBox.Show("01"); //For Debug, is executed
            string myString = myStreamReader.ReadLine();

            MessageBox.Show("02"); //For Debug, is NOT executed

            label1.Text = myString;

            myProcessR.WaitForExit();
            myProcessR.Close();
            //&lt;&gt;//---------------/ISSUE?--------------------------------
        }
</code></pre>

<p>Python Example (myscript/test01.py) :</p>

<pre><code> aaa = raw_input("&gt; ")
 print "Ok, you say:",aaa
</code></pre>

<p>IMPORTANT Update: I found if i set "myProcessStartInfo.RedirectStandardInput = false", "RedirectStandardOutput" will work, but i will not write...</p>

<p>Do you need that the C# program and the python one work at the same time?
If no, you can gather all the data from the C# program and send them to the python script either as arguments in the command line, or in a file that the two programs share.</p>

<p>To use arguments in a python script you can use the <a href="https://docs.python.org/2/library/argparse.html#module-argparse" rel="nofollow">argparse module</a>.</p>

c# python