
org.rhq.server.control.ProcessHandler Maven / Gradle / Ivy
The newest version!
/*
*
* * RHQ Management Platform
* * Copyright (C) 2005-2012 Red Hat, Inc.
* * All rights reserved.
* *
* * This program is free software; you can redistribute it and/or modify
* * it under the terms of the GNU General Public License, version 2, as
* * published by the Free Software Foundation, and/or the GNU Lesser
* * General Public License, version 2.1, also as published by the Free
* * Software Foundation.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License and the GNU Lesser General Public License
* * for more details.
* *
* * You should have received a copy of the GNU General Public License
* * and the GNU Lesser General Public License along with this program;
* * if not, write to the Free Software Foundation, Inc.,
* * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package org.rhq.server.control;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Scanner;
/**
* @author John Sanda
*/
public class ProcessHandler {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
Process process = new ProcessBuilder("/usr/local/bin/rhino").start();
OutputStream stdin = process.getOutputStream ();
InputStream stderr = process.getErrorStream ();
InputStream stdout = process.getInputStream ();
BufferedReader reader = new BufferedReader (new InputStreamReader(stdout));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
writer.write("help");
while (scanner.hasNext()) {
String input = scanner.nextLine();
writer.write(input);
if (input.equals("quit()")) {
break;
}
writer.flush();
String line = reader.readLine();
while (line != null && !line.trim().equals("QUIT")) {
line = reader.readLine();
System.out.println(line);
}
if (line == null) {
break;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy