Ignore my 1st point. I obviously can't read the documentation!. On Thu, 12 Jan 2023 at 17:44, Paul McCulloch <[email protected]> wrote:
> I think you want BufferedReader reader = new BufferedReader(new > InputStreamReader(p.get*Output*Stream())); > > 'client' just launches another JVM. It might be simpler (and cross > platform if that matters) to just use the client class directly. > > On Thu, 12 Jan 2023 at 15:32, Domke, Alexander <[email protected]> wrote: > >> Hello all, >> >> >> >> I'm trying to use a Java program to check if the Karaf SSH client that >> comes with the program is working. For this I wrote a simple Java program, >> but the client does not return the result. When I run the command "bash -c >> ./bin/client -u karaf -p karaf \"system:version\"" manually in the console >> it works, but not when I run it through the program. >> >> >> >> >> >> import java.io.BufferedReader; >> >> import java.io.IOException; >> >> import java.io.InputStreamReader; >> >> >> >> public class App { >> >> >> >> public static void main(String[] args) throws Exception { >> >> System.out.println("SSH Client Check"); >> >> testSSHClient(); >> >> } >> >> >> >> public static void testSSHClient() throws Exception { >> >> String commandUnix = "bash -c ./bin/client -u karaf -p karaf >> \"system:version\""; >> >> String clientLoginResult = executeSSHClient(commandUnix); >> >> System.out.println(clientLoginResult); >> >> } >> >> >> >> private static String executeSSHClient(String command) >> >> throws IOException, InterruptedException { >> >> StringBuffer output = new StringBuffer(); >> >> Process p = Runtime.getRuntime().exec(command); >> >> p.waitFor(); >> >> BufferedReader reader = new BufferedReader(new >> InputStreamReader(p.getInputStream())); >> >> >> >> String line = ""; >> >> while ((line = reader.readLine()) != null) { >> >> output.append(line + "\n"); >> >> } >> >> String result = output.toString(); >> >> return result.trim(); >> >> } >> >> } >> >> >> >> Does anyone have any idea what could be the reason for this? >> >> >> >> Regards >> >> Alex >> >> CENIT AG, Industriestrasse 52-54, 70565 Stuttgart, Tel.: +49 711 7825-30, >> Fax: +49 711 7825-4000, Internet: www.cenit.com >> Geschaeftsstellen (Branch Offices): Berlin, Frankfurt, Hamburg, Hannover, >> Muenchen, Oelsnitz, Ratingen, Saarbruecken >> Vorstandsmitglieder (Members of the Board): Peter Schneck, Axelle Maze >> Aufsichtsratsmitglieder (Supervisory Board Members): Rainer Koppitz >> (Vorsitzender des Aufsichtsrats / Chairman of the Supervisory Board), Prof. >> Dr. Isabell Welpe, Ricardo Malta >> Bankverbindungen (Bank Accounts): >> Deutsche Bank (BLZ 600 700 70) Kto. 1661 040 IBAN : DE85 6007 0070 0166 >> 1040 00 SWIFT-CODE : DEUTDESS, >> Commerzbank (BLZ 600 400 71) Kto. 532 015 500 IBAN : DE83 6004 0071 0532 >> 0155 00 SWIFT-Code : COBADEFF600, >> Registergericht (Registry court): Amtsgericht Stuttgart >> Handelsregister (Commercial Register): HRB Nr. 19117 >> Umsatzsteuer (VAT) ID: DE 147 862 777 >> >
