管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-08-03 2e2f1f542db7d709813efd6dcce14e3bc076bfa0
ExportMap/cs/Tools.cs
@@ -166,9 +166,12 @@
        /// <summary>
        /// 执行CMD
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="cmd">命令行</param>
        /// <param name="isPy">是否为QGIS Py脚本</param>
        /// <param name="isOut">是否输出错误</param>
        /// <returns>执行结果或出错信息</returns>
        public static string ExecCmd(string cmd, bool isPy = false, bool isOut = false)
        public static string ExecCmd(SysTask task, string cmd, bool isPy = false, bool isOut = false)
        {
            List<string> list = new List<string>();
            if (isPy)
@@ -180,7 +183,7 @@
            }
            list.Add(cmd);
            string str = ExecCmd(list, isOut);
            string str = ExecCmd(task, list, isOut);
            return str;
        }
@@ -188,9 +191,11 @@
        /// <summary>
        /// 执行CMD
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="list">命令集合</param>
        /// <param name="isOut">是否输出错误</param>
        /// <returns>执行结果或出错信息</returns>
        public static string ExecCmd(List<string> list, bool isOut = false)
        public static string ExecCmd(SysTask task, List<string> list, bool isOut = false)
        {
            string str = null;
            try
@@ -204,6 +209,8 @@
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.Start();
                //p.Id;
                StreamWriter si = p.StandardInput; // 标准输入流 
                StreamReader so = isOut ? p.StandardOutput : null; // 标准输出流 
@@ -239,6 +246,56 @@
        }
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="list">命令集合</param>
        public static string ExecCmd(List<string> list)
        {
            string str = null;
            Process p = null;
            try
            {
                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 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();
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                str = ex.Message;
            }
            finally
            {
                if (p != null)
                {
                    p.Close();
                    p = null;
                }
            }
            return str;
        }
        /// <summary>
        /// 创建数据发布类
        /// </summary>
        public static SysPublish NewPublish(SysMeta meta, XYZArgs args, string url, string path)