百科问答小站 logo
百科问答小站 font logo



C#程序如何调用Python程序? 第1页

  

user avatar   Ivony 网友的相关建议: 
      

建议你先看一下错误信息是什么。

方案一:

先进入命令行后再用命令行打开C#程序,C#程序运行中出现的任何异常,其实都会直接输出到命令行,这样一来就能知道出现什么错误了。

方案二:

在代码的最外层加上异常捕获,像这样:

       class ControlPython {   public void startexe()   {     try     {       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();     }     catch( Exception e )     {       Console.WriteLine( e );     }      Console.ReadLine();   } }     

另外我注意到最后的那个sepy变量/成员似乎没有定义。




  

相关话题

  以现在的编程手段做得不到真随机吗? 
  计算 2 的 64 次方有什么特殊技巧? 
  linux 在终端打开程序后关闭终端,程序也跟着关闭了怎么办? 
  C#是如何将不合理的数字转换为Enum类型的? 
  以后真的是人人都会编程的时代吗? 
  当你读代码时在读什么? 
  当你学会了什么之后感觉自己的编程算是入门了? 
  你目前写出的最大的 Bug 是怎样的? 
  物理专业学生应该具备哪些数学素养? 
  不同编程语言的程序员之间有鄙视链么? 

前一个讨论
是否存在不可能匹配到任何字符串的正则表达式?
下一个讨论
可否只单买一个正版 Microsoft Word?





© 2025-02-20 - tinynew.org. All Rights Reserved.
© 2025-02-20 - tinynew.org. 保留所有权利