百科问答小站 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变量/成员似乎没有定义。




  

相关话题

  对于同一段代码,循环次数有限且已知,do和for之中哪一个的效率更高?为什么? 
  C# 中如何在不使用 async和await 关键字的情况下构建一个按照顺序执行的 Task 集合? 
  Python中for i in somelist,如果在for循环内改变somelist会发生什么? 
  Linux的ls -l命令输出的第二列的数字代表什么? 
  新手该如何使用 GitHub? 
  为什么说CMU的CS Master很好申请? 
  为什么 Java 只有值传递,但 C# 既有值传递,又有引用传递,这种语言设计有哪些好处? 
  为什么程序员不自己单干? 
  准大一,零基础自学C语言,有什么简单易懂的自学书籍和课程推荐吗? 
  熊猫烧香病毒的技术性有多高? 

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





© 2025-05-10 - tinynew.org. All Rights Reserved.
© 2025-05-10 - tinynew.org. 保留所有权利