| | |
| | | /// <returns>执行结果或出错信息</returns> |
| | | public static String ExecCmd(string cmd, bool isPy = false) |
| | | { |
| | | 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("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\""); |
| | | //list.Add("exit()"); |
| | | } |
| | | list.Add(cmd); |
| | | |
| | | string str = ExecCmd(list); |
| | | |
| | | return str; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 执行CMD |
| | | /// </summary> |
| | | /// <param name="list">命令集合</param> |
| | | /// <returns>执行结果或出错信息</returns> |
| | | public static string ExecCmd(List<string> list) |
| | | { |
| | | string str = null; |
| | | try |
| | | { |
| | |
| | | p.StartInfo.FileName = "cmd.exe"; |
| | | p.StartInfo.UseShellExecute = false; |
| | | p.StartInfo.CreateNoWindow = true; |
| | | //p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; |
| | | p.StartInfo.RedirectStandardInput = true; |
| | | p.StartInfo.RedirectStandardOutput = true; |
| | | p.StartInfo.RedirectStandardError = true; |
| | |
| | | StreamReader so = p.StandardOutput; // 标准输出流 |
| | | StreamReader se = p.StandardError; // 标准错误流 |
| | | |
| | | LogOut.Info("cmd = " + cmd); |
| | | LogOut.Info("cmd = " + string.Join(",", list)); |
| | | si.AutoFlush = true; |
| | | if (isPy) |
| | | foreach (string cmd in list) |
| | | { |
| | | si.WriteLine("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\""); |
| | | si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\qgis_process-qgis-ltr.bat\""); |
| | | //si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\""); |
| | | //si.WriteLine("exit()"); |
| | | si.WriteLine(cmd); |
| | | } |
| | | si.WriteLine(cmd); |
| | | si.WriteLine("exit"); |
| | | |
| | | string info = so.ReadToEnd(); |