For some reason I'm not understanding why I'm having an issue in my exec
command and I believe I followed the documentation and examples I've referenced correctly. When I run this command in the terminal I do not have an issue:
gitleaks --repo=https://github.com/user/repo -v --username=foo --password=bar
but when I try to code it as a module so I can call upon it in package.json:
const { exec } = require("child_process")
const test = `gitleaks --repo=https://github.com/user/repo -v --username=foo --password=bar`
const execRun = (cmd) => {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) reject(error)
resolve(stdout ? stdout : stderr)
})
})
}
(async () => {
try {
const testing = await execRun(test)
console.log(testing)
} catch (e) {
console.log(e)
}
})()
but I continue to get the error:
{ Error: Command failed: gitleaks --repo=https://github.com/user/repo -v --username=foo --password=bar
at ChildProcess.exithandler (child_process.js:294:12)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Socket.stream.socket.on (internal/child_process.js:389:11)
at Socket.emit (events.js:198:13)
at Pipe._handle.close (net.js:606:12)
killed: false,
code: 1,
signal: null,
cmd:
'gitleaks --repo=https://github.com/user/repo -v --username=foo --password=bar' }
I've tried to research my issue to see if I'm missing something and read:
- nodejs exec command failing with no useful error message
- Node Child Process Exec Command Failed with error code 1
- nodejs exec command fails for some windows commands with no clear error message
- NodeJS Child Process EXEC Command Failed with NVM Permission denied OSX
Why does my exec
command fail but I can pass the same command in the terminal and it works?