管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-07 8d7a67ab1d635cb954337d8a767878ae526dd3dc
ExportMap/cs/Tools.cs
@@ -80,6 +80,19 @@
        }
        /// <summary>
        /// 获取Py初始化参数
        /// </summary>
        public static string[] PyInitArgs
        {
            get
            {
                string args = GetSetting("pyInitArgs");
                return args.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            }
        }
        /// <summary>
        /// 字节格式化
        /// </summary>
        public static string FormatBytes(long bytes)
@@ -188,8 +201,9 @@
            List<string> list = new List<string>();
            if (isPy)
            {
                list.Add("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\"");
                list.Add("\"C:\\Program Files\\QGIS 3.16\\bin\\qgis_process-qgis-ltr.bat\"");
                //list.Add("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\"");
                //list.Add("\"C:\\Program Files\\QGIS 3.16\\bin\\qgis_process-qgis-ltr.bat\"");
                list.AddRange(PyInitArgs);
                //list.Add("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\"");
                //list.Add("exit()");
            }
@@ -377,35 +391,23 @@
        /// 执行命令
        /// </summary>
        /// <param name="list">命令集合</param>
        public static string ExecCmdForWin(List<string> list, bool noWin = false)
        public static string ExecExe(string exe, string args, bool noWin = true)
        {
            string str = null;
            Process p = null;
            try
            {
                p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.FileName = exe;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = noWin;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                if (!string.IsNullOrEmpty(args)) p.StartInfo.Arguments = args;
                p.Start();
                StreamWriter si = p.StandardInput;
                StreamReader se = p.StandardError;
                LogOut.Info("cmd = " + string.Join(",", list));
                si.AutoFlush = true;
                foreach (string cmd in list)
                {
                    si.WriteLine(cmd);
                }
                si.WriteLine("exit");
                str = se.ReadToEnd();
                se.Close();
                si.Close();
                p.WaitForExit();
            }
            catch (Exception ex)
            {