linux下:
String[] command = { "/bin/sh", "-c", cmmd };
Process ps = Runtime.getRuntime().exec(command );
windows下:
String[] command = { "cmd", "/c", cmmd };
Process ps = Runtime.getRuntime().exec(command );
本文介绍如何在Linux和Windows系统中使用Java执行不同命令的方法。在Linux环境下,通过调用/bin/sh并传递参数来运行命令;而在Windows环境中,则利用cmd.exe执行相应指令。这两种方式为开发者提供了跨平台操作系统的解决方案。
linux下:
String[] command = { "/bin/sh", "-c", cmmd };
Process ps = Runtime.getRuntime().exec(command );
windows下:
String[] command = { "cmd", "/c", cmmd };
Process ps = Runtime.getRuntime().exec(command );

被折叠的 条评论
为什么被折叠?