我想在java中运行一个像视频游戏这样的程序并让它输出它在java中所做的一切,这可能吗?为了澄清一切,我想看看游戏在做什么方面的输出。我知道它可能无法完全理解,因为它会使用不同的程序语言。这里有人记得使用gameshark/gamegenie破解游戏代码吗?这就是我想做的事情。
到目前为止,我尝试了运行时和 processbuilder,但它什么也没做。
下面是我的代码:
public class ProcessW {
public static void main(String[] args) throws IOException {
String command = "...my game...";
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectErrorStream(true);
Process proc = pb.start();
java.io.InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
int exit = -1;
while ((line = br.readLine()) != null) {
// Outputs your process execution
System.out.println(line);
try {
exit = proc.exitValue();
if (exit == 0) {
// WinProcess finished
}
} catch (IllegalThreadStateException t) {
// The process has not yet finished.
// Should we stop it?
//if (processMustStop())
// processMustStop can return true
// after time out, for example.
proc.destroy();
}
}
}
}