Java Code Examples for ch.ethz.ssh2.Session#getStderr()

The following examples show how to use ch.ethz.ssh2.Session#getStderr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSH2Util.java    From redis-manager with Apache License 2.0 6 votes vote down vote up
/**
 * 执行Shell脚本或命令
 *
 * @param machine
 * @param commands
 * @return
 */
public static String execute(Machine machine, String commands) throws Exception {
    String result;
    Connection connection = null;
    try {
        connection = getConnection(machine);
        // 打开一个会话
        Session session = connection.openSession();
        session.execCommand(commands);
        InputStream in = session.getStdout();
        result = processStandardOutput(in);
        InputStream errorIn = session.getStderr();
        result += processStandardOutput(errorIn);
    } finally {
        close(connection);
    }
    return result;
}
 
Example 2
Source File: SUTTest.java    From bestconf with Apache License 2.0 6 votes vote down vote up
@Override
public void startTest(){
	Session session=null;
	try {
		getConnection();
		if(connection==null)
			throw new IOException("Unable to connect the server!");
	    session = connection.openSession();
		session.execCommand(shellofstartTest);
		System.out.println("Here is some information about the remote host:");
		InputStream stderr = new StreamGobbler(session.getStderr());
		BufferedReader br = new BufferedReader(new InputStreamReader(stderr));
		InputStream stdout = new StreamGobbler(session.getStdout());
		BufferedReader stdbr = new BufferedReader(new InputStreamReader(stdout));
		System.out.println("Test had been started successfully!");
	} catch (IOException e) {
		e.printStackTrace();
		System.exit(-1);
	}finally{
		if(session != null)
    		   session.close();
    	   closeConnection();
	}
}