Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.IO;
- namespace Run_Python_From_C_Sharp
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string python = @"C:\Python27\python.exe";
- string myPythonApp = @"C:\Users\Efim\Documents\python\test.py";
- int x = (int)numeric_x.Value;
- int y = (int)numeric_y.Value;
- ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
- myProcessStartInfo.UseShellExecute = false;
- myProcessStartInfo.RedirectStandardOutput = true;
- myProcessStartInfo.Arguments = myPythonApp;
- using (Process myProcess = new Process())
- {
- myProcess.StartInfo = myProcessStartInfo;
- lb_status.Text = "Status: Calling Python script with arguments " + x + " and " + y;
- myProcess.Start();
- using (StreamReader myStreamReader = myProcess.StandardOutput)
- {
- string myString = myStreamReader.ReadLine();
- lb_status.Text = "Status: Value received from script: " + myString;
- myProcess.WaitForExit();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement