Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
命令在终端工作,但不';不要使用node.js_Node.js_7zip - Fatal编程技术网

命令在终端工作,但不';不要使用node.js

命令在终端工作,但不';不要使用node.js,node.js,7zip,Node.js,7zip,我尝试在Linux上用7z解包img文件。在终端,它可以正常工作: 7z x myimg.img 但当我尝试从node.js脚本执行此操作时,失败了: const childProcess = require('child_process'); childProcess.exec('7z x myimg.img', (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`);

我尝试在Linux上用7z解包img文件。在终端,它可以正常工作:

7z x myimg.img
但当我尝试从node.js脚本执行此操作时,失败了:

const childProcess = require('child_process');

childProcess.exec('7z x myimg.img', (error, stdout, stderr) => {
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
  console.error(`stderr: ${stderr}`);
});
我得到这个信息:

exec错误:错误:命令失败:7z x myimg.img 错误:myimg.img 无法将文件作为存档文件打开


如果我运行命令
where is 7z
我会得到相同的路径。

您想提取和
.img
文件吗?您确定该文件确实包含存档吗?或者您可能将
x
a
?@zokkkker13 7z full-can混合起来提取.img文件。它在终端中工作。你是对的,工作很好,很高兴知道。你的脚本和我的机器配合得很好。我想知道那
sudo
是从哪里来的。可能您没有读取该文件的权限。你能排除吗?@zokkker13这只是打字错误。我尝试了不同的变体并复制了错误的消息。我的img文件拥有所有权限。我给了他们
chmod 777 myimg.img
如果执行
ls myimg.img
,会发生什么?也许CWD出了问题?