我剛剛啓動了一個AI機器人遊戲nethack
,我無法繞過源代碼中的「人工檢查」。我說的是一段代碼是nethack/sys/unix/unixunix.c
:如何從Node.js連接到nethack?
#ifdef TTY_GRAPHICS
/* idea from rpick%[email protected]
* prevent automated rerolling of characters
* test input (fd0) so that tee'ing output to get a screen dump still
* works
* also incidentally prevents development of any hack-o-matic programs
*/
/* added check for window-system type -dlc */
if (!strcmp(windowprocs.name, "tty"))
if (!isatty(0))
error("You must play from a terminal.");
#endif
我在JavaScript中,(更具體的Node.js),以及由於上述工作,它不會讓我從節目播放,儘管我正在產生一個bash shell子進程並告訴它開始nethack
。我需要找出一種方法來繞過上述而不重新編譯源代碼。
我使用的是當前的代碼是:
"use strict";
var env = { TERM: 'tty' };
for (var k in process.env) {
env[k] = process.env[k];
}
var terminal = require('child_process').spawn('bash', [], {
env: env,
});
terminal.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
terminal.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
setTimeout(function() {
terminal.stdin.write('nethack');
terminal.stdin.end();
}, 1000);
程序的輸出是:
stdout: You must play from a terminal.
child process exited with code 1
什麼的Node.js/JavaScript的(而不是任何其他語言或框架,如果可能)我可以用黑魔法來解決這個問題嗎?
我不確定這一點,你可能想看看節點的[TTY模塊](http://nodejs.org/api/tty.html)。此外,[此線程](http://groups.google.com/group/nodejs/browse_thread/thread/6fd25d16b250aa7d)可能會引起您的興趣。 – 2012-03-22 11:16:04
是的,我已經檢出了TTY模塊:似乎v0.6 +棄用了'tty.open()'方法,這可能是我想要的,但該方法使用了不推薦的'process.binding 'stdio')'調用,我找不到任何文檔。我會檢查線程。謝謝。 – chrisdotcode 2012-03-22 16:02:43