how to run a command at terminal from java program?

前端 未结 6 2163
孤城傲影
孤城傲影 2020-11-29 03:14

I need to run a command at terminal in Fedora 16 from a JAVA program. I tried using

Runtime.getRuntime().exec(\"xterm\"); 

but this just op

6条回答
  •  囚心锁ツ
    2020-11-29 03:52

    I don't know why, but for some reason, the "/bin/bash" version didn't work for me. Instead, the simpler version worked, following the example given here at Oracle Docs.

    String[] args = new String[] {"ping", "www.google.com"};
    Process proc = new ProcessBuilder(args).start();
    

提交回复
热议问题