A java library of common unix commands (specifically dd)?
I need to use the dd command for blocking some files, and would rather do 开发者_高级运维it without calling it via shell.
Is there a class library already written, or should I roll my own blocker unblocker?
Basically equivalent to going:
dd if=foo.log of=fooblocked.log cbs=79 conv=block
Runtime.getRuntime().exec()
executes the command passed in a shell (a command prompt in Windows) the shell defaults to the programs working directory.
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();
}
}
If you need the program to wait until the command completes, you can use p.waitFor()
.
精彩评论