【问题标题】:Electron - Network path cannot be found电子 - 找不到网络路径
【发布时间】:2017-06-21 18:23:24
【问题描述】:

我正在尝试使用网络路径在 Electron 中运行批处理文件。我正在使用的功能是:

    function cpSixHundred() {
  require('child_process').exec("file:\\\\LSC-SA-NAS1\\Departments\\Information Technology\\Software\\Zebra Label Printer Reset Counters", function(err, stdout, stderr) {
    if (err) {
      // Ooops.
      // console.log(stderr);
      return console.log(err);
    }

    // Done.
    console.log(stdout);
  });
}

我得到的错误是:

Error: Command failed: \\LSC-SA-NAS1\Departments\Information 
Technology\Software\Zebra Label Printer Reset Counterstest.bat
'\\LSC-SA-NAS1\Departments\Information' is not recognized as an internal or 
external command,
operable program or batch file.

我知道它不喜欢网络路径中的空间。我尝试了许多引号和字符串连接的组合,但仍然没有运气。

提前谢谢你。

【问题讨论】:

标签: javascript electron


【解决方案1】:

您需要使用单引号字符串并在文件路径周围加上双引号。

这方面的一个例子取自 node js 文档:

https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

exec('"/path/to/test file/test.sh" arg1 arg2');
//Double quotes are used so that the space in the path is not interpreted as
//multiple arguments

编辑:

如果可以,请避免在函数调用中使用模块,这会降低您的应用程序的速度,而且大多数情况下这是一种不好的做法。

// put all required modules on top of your page
var childProcess = require('child_process');

function cpSixHundred() {
   childProcess.exec('"file:\\\\LSC-SA-NAS1\\Departments\\Information Technology\\Software\\Zebra Label Printer Reset Counters"', function(err, stdout, stderr) {
      if (err) {
         // Ooops.
         // console.log(stderr);
         return console.log(err);
      }

      // Done.
      console.log(stdout);
   });
}

【讨论】:

    猜你喜欢
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 2015-03-04
    • 2017-07-04
    相关资源
    最近更新 更多