| | |
| | | } |
| | | |
| | | /// <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) |
| | |
| | | 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()"); |
| | | } |
| | |
| | | /// 执行命令 |
| | | /// </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) |
| | | { |