java如何通过其他程序更新“历史记录”
在ubuntu服务器上,我可以按向上箭头显示我使用的最后一个命令行,例如,我们可以通过history -r
修改它
$>history
... some command here
...
$> history -r hello.file
$>cat hello.file
aa
$>history
... some command here
...
aa
当然,当我此时按下向上箭头时,命令行会给我“aa”
所以,我想要一些程序来帮助我做到这一点
我的Java示例代码是
Runtime r = Runtime.getRuntime();
Process p = r.exec("/bin/bash history -r hello.file");
p.waitFor();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = b.readLine()) != null) {
System.out.println(line);
}
b.close();
但它不起作用,java也没有打印任何异常
我还通过一个简单的bash文件进行了测试
我的bash文件:
#!/bin/bash
history -r hello.file
我的测试结果是
$>history
... some command here
...
$>sh my_bash_file.sh
$>history
... some command here
...
它仍然不起作用
如何通过程序更新“历史记录”
不可能吗
共 (0) 个答案