Search code examples
node.jstty

child_process.execSync('tty') causes error


Anyone know why I get the following error, when I run

const cp = require('child_process');
const _tty = cp.execSync('tty');

...we get this error:

Error: Command failed: tty

    at checkExecSyncError (child_process.js:488:13)
    at Object.execSync (child_process.js:528:13)
    at Server (/Users/Olegzandr/WebstormProjects/oresoftware/suman/lib/create-suman-server.js:52:13)
    at watch (/Users/Olegzandr/WebstormProjects/oresoftware/suman/lib/watching/add-watcher.js:84:3)
    at module.exports (/Users/Olegzandr/WebstormProjects/oresoftware/suman/lib/helpers/watch-init.js:56:41)
    at Object.<anonymous> (/Users/Olegzandr/WebstormProjects/oresoftware/suman/index.js:557:38)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12) 

No idea why the error happens, since I can run "tty" from any terminal (without root permissions?)


Solution

  • With some help from the Node.js experts, I figured this out.

    this will give you an unspecified error (the error in the OP)

    const _tty = cp.execSync('tty');
    

    however, this will get you what you are looking for:

    const _tty = cp.execSync('tty', {stdio:['inherit','pipe','pipe']});