From 2f38d9ee5f607a1078258a8575acf9600b9e8595 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 13 三月 2023 16:54:13 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/Tool.cs |   72 +++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/ExportMap/cs/Tool.cs b/ExportMap/cs/Tool.cs
index f3afc7c..b7855b5 100644
--- a/ExportMap/cs/Tool.cs
+++ b/ExportMap/cs/Tool.cs
@@ -3,6 +3,7 @@
 using System.Collections.Generic;
 using System.Configuration;
 using System.Data.Common;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Reflection;
@@ -16,8 +17,14 @@
 {
     public class Tool
     {
+        /// <summary>
+        /// 鍩虹鐩綍
+        /// </summary>
         public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
 
+        /// <summary>
+        /// 瀛楄妭鏍煎紡鍖�
+        /// </summary>
         public static string FormatBytes(long bytes)
         {
             string[] Suffix = { "Byte", "KB", "MB", "GB", "TB" };
@@ -31,11 +38,17 @@
             return String.Format("{0:0.##}{1}", dblSByte, Suffix[i]);
         }
 
+        /// <summary>
+        /// 鑾峰彇璁剧疆
+        /// </summary>
         public static string GetSetting(string key)
         {
             return ConfigurationManager.AppSettings[key];
         }
 
+        /// <summary>
+        /// 鑾峰彇Db鍙傛暟
+        /// </summary>
         public static List<DbParameter> GetParams<T>(string sql, T t)
         {
             List<DbParameter> list = new List<DbParameter>();
@@ -65,6 +78,9 @@
             return list;
         }
 
+        /// <summary>
+        /// 鍒涘缓鐩綍
+        /// </summary>
         public static void CreateDirectory(string dir)
         {
             WindowsIdentity wi = WindowsIdentity.GetCurrent();
@@ -76,6 +92,9 @@
             Directory.CreateDirectory(dir, ds);
         }
 
+        /// <summary>
+        /// 鍏嬮殕瀵硅薄
+        /// </summary>
         public static T Clone<T>(T source) where T : new()
         {
             if (!typeof(T).IsSerializable)
@@ -98,5 +117,56 @@
                 return (T)formatter.Deserialize(stream);
             }
         }
+
+        /// <summary>
+        /// 鎵цPython
+        /// </summary>
+        /// <param name="cmd">鍛戒护琛�</param>
+        /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
+        public static String ExecPython(string cmd)
+        {
+            string str = null;
+            try
+            {
+                Process p = new Process();
+                p.StartInfo.FileName = "cmd.exe";
+                p.StartInfo.UseShellExecute = false;
+                p.StartInfo.CreateNoWindow = true;
+                p.StartInfo.RedirectStandardInput = true;
+                p.StartInfo.RedirectStandardOutput = true;
+                p.StartInfo.RedirectStandardError = true;
+                p.Start();
+
+                StreamWriter si = p.StandardInput; // 鏍囧噯杈撳叆娴� 
+                StreamReader so = p.StandardOutput; // 鏍囧噯杈撳嚭娴� 
+                StreamReader se = p.StandardError; // 鏍囧噯閿欒娴�
+
+                LogOut.Info("cmd = " + cmd);
+                si.AutoFlush = true;
+                si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\"");
+                si.WriteLine(cmd);
+                si.WriteLine("exit");
+
+                string info = so.ReadToEnd();
+                str = se.ReadToEnd();
+
+                if (!string.IsNullOrEmpty(info)) LogOut.Debug(info);
+                if (!string.IsNullOrEmpty(str)) LogOut.Error(str);
+                if (p.HasExited == false) p.Kill();
+
+                se.Close();
+                so.Close();
+                si.Close();
+                p.Close();
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.StackTrace);
+                str = ex.Message;
+            }
+
+            return str;
+
+        }
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.9.3