title: execute python functions return results to c#
body: <p>I have a python file filled with functions that I need to post using jsonrpc. Currently I can post the functions to the desired site and get results in python. But now I want to run the the python script from C#, get the results and do something with them. I am having troubles getting the python script to run and return the results to C#</p>
  
  <p>I prefer to not download IronPython, so a solution that doesn't use it would be helpful.</p>
  
  <p>What happens now is it there is a shell that pop ups quick then disappears when the <code>Process.Start(start))</code> line is hit. Then nothing is returned to the reader.  </p>
  
  <p>Python Code:</p>
  
  <pre><code>#!usr/bin/python
  
  import sys
  import json
  import jsonrpclib
  
  def dc_906(orderid, givexNum, amount):
  
      jsonrpclib.config.use_jsonclass = True
  
      server = jsonrpclib.Server('https://dev-dataconnect.com:50')
      ping1 = server.dc_906('en', orderid, 'userid', 'password', num, amount)
  
      print jsonrpclib.history.response #this could be a "return" instead of print, not sure.
  
  if __name__ == "__main__":
  
      function = sys.argv[1]
      orderid = sys.argv[2]
      num = sys.argv[3]
      amount = sys.argv[4]
  
      if function == 'dc_906':
          dc_906(orderid, num, amount)
  </code></pre>
  
  <p>C# code to execute the process (gotten from: <a href="https://stackoverflow.com/questions/11779143/run-a-python-script-from-c-sharp">How do I run a Python script from C#?</a>)</p>
  
  <pre><code>try
  {
      ProcessStartInfo start = new ProcessStartInfo();
  
      start.FileName = @"C:\Python27\python.exe"; //full path to python.exe
      //start.FileName = @"C:\Windows\system32\cmd.exe";
      //start.Arguments = string.Format("{0} {1} {2} {3}", @"C:\Users\J1035\Documents\Python27\GiveX_python\test.py", "123456789", "603628982592000186162", 20.00);
      start.Arguments = string.Format("{0} {1}", @"C:\Users\J1035\Documents\Python27\GiveX_python\test.py", "123456789 603628982592000186162 20.00");
  
      start.UseShellExecute = false;
      start.RedirectStandardOutput = true;
  
      using(Process process = Process.Start(start))
      using (StreamReader reader = process.StandardOutput)
      {
          string foo = reader.ReadToEnd();
          TxtResultOutput.Text += foo;
      }
  
  }
  catch (Exception ex)
  {
      var foo = ex.Message;
  }
  </code></pre>
  
  <p>Results from running the python script on the command line:</p>
  
  <p><img src="https://i.stack.imgur.com/ZAU1v.png" alt="enter image description here"></p>