title: Why is my exec command failing but works if the command is passed in the terminal?
body: <p>For some reason I'm not understanding why I'm having an issue in my <code>exec</code> 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:</p>
  
  <pre><code>gitleaks --repo=https://github.com/user/repo -v --username=foo --password=bar
  </code></pre>
  
  <p>but when I try to code it as a module so I can call upon it in package.json:</p>
  
  <pre><code>const { exec } = require("child_process")
  const test = `gitleaks --repo=https://github.com/user/repo -v --username=foo --password=bar`
  
  const execRun = (cmd) =&gt; {
    return new Promise((resolve, reject) =&gt; {
      exec(cmd, (error, stdout, stderr) =&gt; {
        if (error) reject(error)
        resolve(stdout ? stdout : stderr)
      })
    })
  }
  
  (async () =&gt; {
  try {
    const testing = await execRun(test)
    console.log(testing)
  } catch (e) {
    console.log(e)
  }
  })()
  </code></pre>
  
  <p>but I continue to get the error:</p>
  
  <pre><code>{ 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' }
  </code></pre>
  
  <p>I've tried to research my issue to see if I'm missing something and read:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/14319724/nodejs-exec-command-failing-with-no-useful-error-message">nodejs exec command failing with no useful error message</a></li>
  <li><a href="https://stackoverflow.com/questions/34622560/node-child-process-exec-command-failed-with-error-code-1">Node Child Process Exec Command Failed with error code 1</a></li>
  <li><a href="https://stackoverflow.com/questions/52736919/nodejs-exec-command-fails-for-some-windows-commands-with-no-clear-error-message">nodejs exec command fails for some windows commands with no clear error message</a></li>
  <li><a href="https://stackoverflow.com/questions/43725871/nodejs-child-process-exec-command-failed-with-nvm-permission-denied-osx">NodeJS Child Process EXEC Command Failed with NVM Permission denied OSX</a></li>
  </ul>
  
  <p>Why does my <code>exec</code> command fail but I can pass the same command in the terminal and it works?</p>