开发者

A java library of common unix commands (specifically dd)?

开发者 https://www.devze.com 2023-03-17 12:15 出处:网络
I need to use the dd command for blocking some files, and would rather do 开发者_高级运维it without calling it via shell.

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().

0

精彩评论

暂无评论...
验证码 换一张
取 消