2016-11-15 136 views
1

任何人都知道,爲什麼我收到以下錯誤,當我運行child_process.execSync( 'TTY')會導致錯誤

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

...我們得到這個錯誤:

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) 

不知道爲什麼發生錯誤,因爲我可以從任何終端運行「tty」(沒有root權限?)

回答

1

在Node.js專家的幫助下,我明白了這一點。

這會給你一個未指定的錯誤(在OP錯誤)

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

但是,這將讓你你在找什麼:

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