We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The following Code is not returning any command output. If anyone can help me here I'd be really happy.
public String cmd( String command) throws Exception { try{ String username = MainActivity._user; String password = MainActivity._pass;; String hostname = MainActivity._host; String port = MainActivity._port; JSch jsch = new JSch(); Session session = jsch.getSession(username, hostname, Integer.parseInt(port)); session.setPassword(password); // Avoid asking for key confirmation Properties prop = new Properties(); prop.put("StrictHostKeyChecking", "no"); session.setConfig(prop); session.connect(); // SSH Channel ChannelExec channelssh = (ChannelExec) session.openChannel("exec"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); channelssh.setOutputStream(baos); channelssh.setCommand(command); channelssh.connect(); while(true){ if(channelssh.isClosed()){ break; } } channelssh.disconnect(); return baos.toString(); } catch (Exception e){ Log.e("ControlActivity-Login:", e.getMessage()); return "ERROR"; } }
Although the same function in MainActivity.java does.
public static String executeRemoteCommand( String username, String password, String hostname, int port, String command) throws Exception { try{ hostname = hostname.replace(" ", ""); JSch jsch = new JSch(); Session session = jsch.getSession(username, hostname, 22); session.setPassword(password); // Avoid asking for key confirmation Properties prop = new Properties(); prop.put("StrictHostKeyChecking", "no"); session.setConfig(prop); session.connect(); // SSH Channel ChannelExec channelssh = (ChannelExec) session.openChannel("exec"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); channelssh.setOutputStream(baos); channelssh.setCommand(command); channelssh.connect(); while(true){ if(channelssh.isClosed()){ break; } } channelssh.disconnect(); return baos.toString(); } catch (Exception e){ Log.e("MainActivity-Login:", e.getMessage()); return "ERROR"; } }
The text was updated successfully, but these errors were encountered:
In der ersten Klasse steht: String port = MainActivity._port; Aber in der MainActivity Klasse ist es ein Integer. int port,
String port = MainActivity._port;
int port,
Versuch in der ersten Klasse das zuschreiben statt den String int port = MainActivity._port;
int port = MainActivity._port;
Und bei dem Passwort sind 2 Semikolon am Ende.
Sorry, something went wrong.
Danke ich werd mir das sobald ich von der Arbeit daheim bin mal ansehen und fixen. Weißt du zufällig auch wieso die Methode keinen Wert zurück gibt?
Suche immer noch den Fehler aber finde einfach keinen. Oder du hast die Methode gar nicht aufgerufen. Ansonsten finde ich keinen Fehler im Code.
Aufgerufen wird sie meines Wissens eh sonst würden die nicht gehen aber dennoch erhalte ich keinen Rückgabewert was halt komisch ist aber ja.
No branches or pull requests
The following Code is not returning any command output. If anyone can help me here I'd be really happy.
Although the same function in MainActivity.java does.
The text was updated successfully, but these errors were encountered: