linux 下 java 执行 shell 命令

    技术2025-02-04  23

     

     

    以下是通过java执行shell命令启动hypertable 数据库的 例子。 

    /** * 启动数据库服务 * @return */ public String startUp() { // 此处的命令是写死的, String commands = "ht start all-servers local"; //String commands = "ping 192.168.1.100"; Process p ; try { p = Runtime.getRuntime().exec(commands); if(p.waitFor()==0) { msg = "服务启动成功!"; } else { msg = "服务启动失败!"; } } catch (IOException e) { msg = "服务启动失败!"; e.printStackTrace(); } catch (InterruptedException e) { msg = "服务启动失败!"; e.printStackTrace(); } catch (Exception e) { msg = "服务启动失败!"; e.printStackTrace(); } return "ok"; }

    最新回复(0)