首页 > 解决方案 > 使用 spawnSync 和 CUPS 命令行的 EACCES 错误

问题描述

我在运行此 CUPS 命令时遇到了问题:取消所有打印机上的所有作业的选项在cancel -a哪里。-a

这是控制台中的所有输出:

error: Error: spawnSync /home/finsoft EACCES
      at Object.spawnSync (internal/child_process.js:1041:20)
      at spawnSync (child_process.js:616:24)
      at Object.cancelAll (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/api/cupsApis.js:155:19)
      at /home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/app.js:80:24
      at Layer.handle [as handle_request] (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/layer.js:95:5)
      at next (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/route.js:137:13)
      at Route.dispatch (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/route.js:112:3)
      at Layer.handle [as handle_request] (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/layer.js:95:5)
      at /home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/index.js:281:22
      at Function.process_params (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/index.js:335:12) {
    errno: 'EACCES',
    code: 'EACCES',
    syscall: 'spawnSync /home/finsoft',
    path: '/home/finsoft',
    spawnargs: [ '-c', 'cancel -u' ]
  },
  status: null,
  signal: null,
  output: null,
  pid: 9826,
  stdout: null,
  stderr: null
}

这是我的 spawnSync 函数:

cancelAll = function () {
  let args = ["-a"];
  let cancelAll = spawnSync("cancel", args, { encoding: "utf-8", shell: '/home/finsoft'});
 // console.log(cancelAll);
  return cancelAll;
};

该选项shell:'/home/finsoft'是我要使用的外壳的路径。

到目前为止我所做的:

1)我尝试将用户在 spawnSync 中使用的根组添加到根组,即 finsoft,我通过运行以下命令对其进行了仔细检查:

 let args = ["-u"];
  args.push('finsoft');
  let uid = spawnSync('id', args, { encoding: "utf-8"});
console.log(uid);

的输出console.log(uid)

{
  status: 0,
  signal: null,
  output: [ null, '1000\n', '' ],
  pid: 8141,
  stdout: '1000\n',
  stderr: ''
}

女巫对应finsoft uid

2)我改变了/home/finsoft这样的权限:

sudo chmod 777 /home/finsoft

结果ls-l

finsoft@finsoft-20351:/home$ ls -l
total 4
drwxrwxrwx 34 finsoft finsoft 4096 Feb 23 09:11 finsoft
  1. 我什至尝试uid:0在 spawnSync 中指定选项,它应该使用 root 用户,并将shell路径更改为默认(/bin/sh),所以我不应该遇到权限或其他要求的问题,但这会产生完全不同的错误:

Error: spawnSync /bin/sh EPERM

我还能尝试什么?

标签: javascriptnode.jslinuxubuntucups

解决方案


推荐阅读