您的位置:首页 > 运维架构 > Shell

linux 下 java 执行 shell 命令

2011-02-10 16:05 786 查看
以下是通过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";
	}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: