* \return boolean
*
* @return
*/
public boolean remoteIsWindowsShell() {
Session objSSHSession = null;
flgIsRemoteOSWindows = false;
try {
// TODO the testcommand should be defined by an option
String checkShellCommand = "echo %ComSpec%";
logger.debug("Opening new session...");
objSSHSession = this.getSshConnection().openSession();
logger.debug("Executing command " + checkShellCommand);
objSSHSession.execCommand(checkShellCommand);
logger.debug("output to stdout for remote command: " + checkShellCommand);
ipsStdOut = new StreamGobbler(objSSHSession.getStdout());
ipsStdErr = new StreamGobbler(objSSHSession.getStderr());
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(ipsStdOut));
String stdOut = "";
while (true) {
String line = stdoutReader.readLine();
if (line == null)
break;
logger.debug(line);
stdOut += line;
}
logger.debug("output to stderr for remote command: " + checkShellCommand);
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(ipsStdErr));
while (true) {
String line = stderrReader.readLine();
if (line == null)
break;
logger.debug(line);
}
// TODO The expected result-string for testing the os should be defined by an option
if (stdOut.indexOf("cmd.exe") > -1) {
logger.debug("Remote shell is a Windows shell.");
flgIsRemoteOSWindows = true;
return true;
}
else {
logger.debug("Remote shell is a Linux/Unix shell.");
}
}
catch (Exception e) {
logger.debug("Failed to check if remote system is windows shell: " + e);
}
finally {
if (objSSHSession != null)
try {
objSSHSession.close();
}
catch (Exception e) {
logger.debug("Failed to close session: ", e);
}
}