Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
C#からPythonを呼ぶ
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SamplePythonCall
{
class Program
{
static void Main(string[] args)
{
run_cmd();
}
static private void run_cmd()
{
string fileName = @"C:\Users\ochi\Documents\temp\test.py";
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "python";//またはPython.exeのフルパス
start.Arguments = fileName;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process =Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write("C#>"+result);
}
}
Console.ReadLine();//終了まち(enterで終了)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment