我需要使用 dd 命令来阻止某些文件,并且宁愿这样做而不通过 shell 调用它。
是否已经编写了一个类库,或者我应该推出自己的阻止程序解除阻止程序?
基本上相当于去:
dd if=foo.log of=fooblocked.log cbs=79 conv=block
Runtime.getRuntime().exec()
执行在 shell(Windows 中的命令提示符)中传递的命令,shell 默认为程序工作目录。
try {
Process p = Runtime.getRuntime().exec("ls -l");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String str = br.readLine();
while(str!=null) {
System.out.println(str);
str=br.readLine();
}
}
如果您需要程序等到命令完成,您可以使用 p.waitFor()
.