常见unix命令(特别是dd)的java库?

发布于 2024-11-18 20:01:39 字数 173 浏览 6 评论 0原文

我需要使用 dd 命令来阻止某些文件,并且宁愿不通过 shell 调用它。

是否已经编写了类库,或者我应该推出自己的拦截器解锁器?

基本上相当于去:

dd if=foo.log of=fooblocked.log cbs=79 conv=block

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流云如水 2024-11-25 20:01:39

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文