我刚刚为游戏nethack启动了一个人工智能机器人,我不能绕过源代码中的“人工检查”。我正在讨论的代码部分是nethack/sys/unix/unixunix.c
#ifdef TTY_GRAPHICS
/* idea from rpick%ucqais@uccba.uc.edu
* 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 (如果可能的话,不要使用任何其他语言或框架)来解决这个问题?
发布于 2013-05-17 09:48:58
这是一种差劲的检查,因为ptys将在isatty()中返回true。Pty是Pseudo terminal的缩写,它允许程序伪装成终端。这就是Xterm和Screen的工作方式。如果检查不允许这些程序通过,您将无法在其中播放NetHack。
我从来没有用过它,但是pty.js绑定到你在C代码中会用到的东西,而且这个接口是有意义的。
https://stackoverflow.com/questions/9815728
复制相似问题