Node.js 使用child_procees.exec firebase函数时权限被拒绝

Node.js 使用child_procees.exec firebase函数时权限被拒绝,node.js,firebase,google-cloud-functions,Node.js,Firebase,Google Cloud Functions,我试图在本地测试中使用nodejs native child_procees.exec()在firebase函数中执行的二进制文件工作正常,但在部署函数时,日志中出现以下错误: Error: Command failed: /user_code/cpdf -pages file.pdf /bin/sh: 1: /user_code/cpdf: Permission denied 有没有一种方法可以授予该权限? 这是我的密码: const exec = require('child_proces

我试图在本地测试中使用nodejs native child_procees.exec()在firebase函数中执行的二进制文件工作正常,但在部署函数时,日志中出现以下错误:

Error: Command failed: /user_code/cpdf -pages file.pdf
/bin/sh: 1: /user_code/cpdf: Permission denied
有没有一种方法可以授予该权限? 这是我的密码:

const exec = require('child_process').exec
var executablePath = path.join(__dirname,'/cpdf')//<-my binary file compiled for linux 32 bits
var filePathIn = path.join(os.tmpdir(),'/file.pdf')
exec(`${executablePath} ${filePathIn} -pages`, 
function(error, stdout, stderr) {
    if (error !== null){
         console.log('error',error)
    }else{
         console.log('ok',stdout)
    }
})
const exec=require('child_process')。exec

var executablePath=path.join(_dirname,'/cpdf')//您需要读取和可执行权限

sudo chmod 755 /user_code/cpdf


我终于找到了解决办法。事实上,
node\u modules
文件夹具有执行权限,因此我在我的package.json中添加了一个npm repo,其中包含必要的二进制文件,然后使用它到可执行文件的路由。以下是我的代码更新:

const exec = require('child_process').exec
var executablePath = path.join(__dirname,'node_modules/cpdf-n/bin/cpdf-linux-64')
var filePathIn = path.join(os.tmpdir(),'/file.pdf')
exec(`${executablePath} -pages ${filePathIn}`, 
function(error, stdout, stderr) {
    if (error !== null){
         console.log('error',error)
    }else{
         console.log('ok',stdout)
    }
})

在部署文件系统之前,文件系统中的unix权限是什么?实际上,我在本地开发中使用的是Windows,Windows二进制文件是cpdf,文件夹没有任何特定权限EAH,因此可能是在没有unix执行权限的情况下上载的。您必须找到一种方法,在使用unix执行权限部署后上载或更改文件。您能给我一些建议吗?我认为不可能修改上传的文件。我甚至尝试过用linux更改文件权限,但显然不起作用。我一整天都在做这个谢谢你的回答但是告诉我一些事。。我必须在哪里执行它?在我的本地文件夹或函数中?。我试图执行下一个代码服务器端exec('bash-c/user_-code/cpdf-pages file.pdf')->“权限被拒绝”exec('chmod 777/user_-code/cpdf')->“权限被拒绝”exec('sudo chmod 777/user_-code/cpdf')->“sudo未找到”我刚刚将我的项目目录从
\desktop
更改为另一个驱动器`d:`。成功了。
const exec = require('child_process').exec
var executablePath = path.join(__dirname,'node_modules/cpdf-n/bin/cpdf-linux-64')
var filePathIn = path.join(os.tmpdir(),'/file.pdf')
exec(`${executablePath} -pages ${filePathIn}`, 
function(error, stdout, stderr) {
    if (error !== null){
         console.log('error',error)
    }else{
         console.log('ok',stdout)
    }
})