PTSV和从C调用python#

2024-06-16 09:48:16 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以在visualstudio中使用python工具来实现对ASP.NETC应用程序和一些python代码?你知道吗

其次,如何从C#调用python脚本?你知道吗

提前谢谢。你知道吗


Tags: 工具代码脚本应用程序aspvisualstudionetc
1条回答
网友
1楼 · 发布于 2024-06-16 09:48:16

至于在C语言中运行python脚本,您可以这样做:

 ProcessStartInfo start = new ProcessStartInfo();
 start.FileName = "path/to/python.exe";
 start.Arguments = string.Format("{0} {1}", cmd, args);
 start.UseShellExecute = false;
 start.RedirectStandardOutput = true;
 using(Process process = Process.Start(start))
 {
     using(StreamReader reader = process.StandardOutput)
     {
         string result = reader.ReadToEnd();
         Console.Write(result);
     }
 }

将python脚本作为cmd传递,将参数作为args传递。你知道吗

相关问题 更多 >