瀏覽代碼

完善日志:调用本地命令出错

Michael Wang 5 年之前
父節點
當前提交
963cfafed5
共有 1 個文件被更改,包括 14 次插入4 次删除
  1. 14 4
      src/utils/nativeExe.js

+ 14 - 4
src/utils/nativeExe.js

@@ -9,19 +9,29 @@ export default function async(exeName, cb) {
       "不在Electron中,调用 " + exeName + " 失败",
     ]);
     createLog({
-      page: window.location.pathname.replace(/\d+/g, ""),
+      page: window.location.pathname,
       action: "不在Electron中,调用 " + exeName + " 失败",
     });
     throw new Error("不在Electron中,调用 " + exeName + " 失败");
   }
   return new Promise(resolve => {
     window.nodeRequire("node-cmd").get(exeName, async (err, data, stderr) => {
-      console.log("exe", err, data, stderr); // 未免过多日志,此处后续可以关闭
+      let stderrConverted;
+      try {
+        const iconv = require("iconv-lite");
+        stderrConverted = iconv.decode(stderr, "cp936");
+      } catch (error) {
+        console.log("convert failed", error);
+        stderrConverted = "convert failed";
+      }
+      console.log(exeName, err, data, stderrConverted); // 未免过多日志,此处后续可以关闭
       createLog({
-        page: window.location.pathname.replace(/\d+/g, ""),
+        page: window.location.pathname,
+        exeName,
         error: JSON.stringify(err),
         data,
         stderr: JSON.stringify(stderr),
+        stderrConverted: JSON.stringify(stderrConverted),
       });
       await new Promise(resolve2 => setTimeout(() => resolve2(), 1000));
       await cb();
@@ -39,7 +49,7 @@ export function fileExists(file) {
       "不在Electron中,调用 fs 失败",
     ]);
     createLog({
-      page: window.location.pathname.replace(/\d+/g, ""),
+      page: window.location.pathname,
       action: "不在Electron中,调用 fs 失败",
     });
     throw new Error("不在Electron中,调用 fs 失败");