sqlcmd命令我没用过,但用Java运行cmd命令好像字符串前面不用加"cmd.exe",参考如下,我试过,大部分命令能执行,但有些不行:
- public class Demo
- {
- public static void main(String[] args) throws Exception
- {
- Process process = Runtime.getRuntime().exec("ipconfig -all");
-
- //获取执行结果输出
- InputStream is = process.getInputStream();
- BufferedReader bufr = new BufferedReader(new InputStreamReader(is, "GBK"));
-
- String len = "";
- while((len = bufr.readLine()) != null)
- {
- System.out.println(len);
- }
- }
- }
复制代码 |