From 1ee6b76e83ae6073e77e48b2246fd773e970ebc2 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 16 三月 2023 14:59:50 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/XYZUtils.cs |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/ExportMap/cs/XYZUtils.cs b/ExportMap/cs/XYZUtils.cs
index f23722f..665740f 100644
--- a/ExportMap/cs/XYZUtils.cs
+++ b/ExportMap/cs/XYZUtils.cs
@@ -3,6 +3,7 @@
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Web;
@@ -58,7 +59,7 @@
 
             WriteText(tifFile, list);
 
-            //string cmd = string.Format("python \"{0}\" -qgz {1} -file \"{2}\" -out \"{3}\" -min {4} -max {5}", PyFile, Qgz, tifFile, xyzPath, args.min, args.max);
+            string cmd = string.Format("python \"{0}\" -qgz {1} -file \"{2}\" -out \"{3}\" -min {4} -max {5}", PyFile, Qgz, tifFile, xyzPath, args.min, args.max);
 
             string pyText = File.ReadAllText(PyFile);
             pyText = pyText
@@ -70,9 +71,10 @@
 
             string newPy = tifFile.Replace(".txt", ".py").Replace("\\", "\\\\");
             File.WriteAllText(newPy, pyText);
-           string cmd = string.Format("exec(open('{0}', 'r', encoding='utf-8').read()) & exit()", newPy);
+           
+            //string cmd = string.Format("exec(open('{0}', 'r', encoding='utf-8').read()) & exit()", newPy);
 
-            err = Tool.ExecCmd(cmd, true);
+            err = ExecCmd(cmd);
 
             if (File.Exists(tifFile)) File.Delete(tifFile);
 
@@ -110,5 +112,57 @@
 
             File.WriteAllText(file, str);
         }
+
+        /// <summary>
+        /// 鎵цCMD
+        /// </summary>
+        /// <param name="cmd">鍛戒护琛�</param>
+        /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
+        public static String ExecCmd(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("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\"");
+                si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\"");
+                //si.WriteLine("exit()");
+                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;
+        }
     }
 }

--
Gitblit v1.9.3