gpt4 book ai didi

javascript - Electron - 找不到网络路径

转载 作者:行者123 更新时间:2023-12-03 04:01:59 25 4
gpt4 key购买 nike

我正在尝试使用网络路径在 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.

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

提前谢谢您。

最佳答案

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

取自 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);
});
}

关于javascript - Electron - 找不到网络路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44683536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com