启动可执行文件,使用Python问题,怎么解决

2025-05-09 21:05:25
推荐回答(1个)
回答1:

class ControlPython{ public void startexe() { Process usepy = new Process(); string path = "\"" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\pyproject.exe" + "\""; usepy.StartInfo.FileName = @"python"; usepy.StartInfo.Arguments = path; usepy.StartInfo.UseShellExecute = false; usepy.StartInfo.RedirectStandardOutput = true; usepy.StartInfo.RedirectStandardInput = true; usepy.StartInfo.RedirectStandardError = true; usepy.StartInfo.CreateNoWindow = false; usepy.OutputDataReceived += (sender, args) => Console.WriteLine("received output: {0}", args.Data); usepy.Start(); sepy.BeginOutputReadLine(); Console.ReadLine(); }