【问题标题】:Running a Linux Command through a Java GUI通过 Java GUI 运行 Linux 命令
【发布时间】:2012-02-07 04:36:30
【问题描述】:

我可以让我的终端显示,但我无法让我的代码运行:并且总是得到异常。知道有什么问题吗?

if (e.getActionCommand() == "Start") {
String command= "/usr/bin/pg_ctl -D /var/lib/pgsql/data -l /var/lib/pgsql/log/pgsql.log     start"; 
Runtime rt = Runtime.getRuntime(); 
try {
rt.exec(command);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

【问题讨论】:

  • 请发布异常和堆栈跟踪。

标签: java linux terminal command runtime.exec


【解决方案1】:

Runtime docs中提到如果要执行command and arguments需要将其作为String数组传递exec(String[] cmdarray)

Runtime doc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    相关资源
    最近更新 更多