您的位置:首页 > 文旅 > 美景 > 重庆安全员证书查询系统_怎样建设网站的步骤_厦门专业做优化的公司_开展网络营销的企业

重庆安全员证书查询系统_怎样建设网站的步骤_厦门专业做优化的公司_开展网络营销的企业

2025/2/27 12:12:39 来源:https://blog.csdn.net/battlestar/article/details/144375921  浏览:    关键词:重庆安全员证书查询系统_怎样建设网站的步骤_厦门专业做优化的公司_开展网络营销的企业
重庆安全员证书查询系统_怎样建设网站的步骤_厦门专业做优化的公司_开展网络营销的企业

需要通过nuget安装ironphthon

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using IronPython.Hosting;namespace 转换json
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void runTransger(object sender, RoutedEventArgs e){string folderPath = Filedir.Text;pythonconfig pconfig = new pythonconfig();// 定义Python 程序pconfig.pythondir = @"D:\02_Study\miniconda\envs\PyT\python.exe";// 定义Python 运行脚本pconfig.scriptdir = @"D:\05_Trick\Trick\utils_pre.py";pythonThread(folderPath,pconfig);}private void pythonThread(string file,pythonconfig pconfig){string args = $"main_Huaatjsontoxml {file}";// 创建一个新的进程来执行Python脚本Console.WriteLine($"{pconfig.pythondir}, {pconfig.scriptdir} {args}");ProcessStartInfo psi = new ProcessStartInfo(pconfig.pythondir, $"{pconfig.scriptdir} {args}");psi.RedirectStandardOutput = true;psi.UseShellExecute = false;Process process = new Process();process.StartInfo = psi;process.Start();// 获取Python脚本的输出结果string output = process.StandardOutput.ReadToEnd();process.WaitForExit();Console.WriteLine($"结果是: {output}"); //python程序最后return的结果}public class pythonconfig{public string pythondir { get; set; }public string scriptdir { get; set; }}}
}

注意:

[1] python主程序运行最后由os.system(“pause”)的需要注释掉

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com