Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 来自应用程序中Raspberry pi怪异文本的jsch shell命令响应_Java_Shell_Android Studio_Jsch - Fatal编程技术网

Java 来自应用程序中Raspberry pi怪异文本的jsch shell命令响应

Java 来自应用程序中Raspberry pi怪异文本的jsch shell命令响应,java,shell,android-studio,jsch,Java,Shell,Android Studio,Jsch,我已经创建了一个应用程序,通过wifi连接到我的raspberry pi,并启动了一个python脚本,但由于某种原因,当我试图在文本视图中打印终端响应时,它们总是会出现奇怪的字符,而不是可读的ascii主动发送shell命令的函数是代码末尾的“PyPiCommands”。有人能解释一下,我用清晰的ASCII字符打印终端响应时遗漏了什么: //The following method starts the initial ssh connection======================

我已经创建了一个应用程序,通过wifi连接到我的raspberry pi,并启动了一个python脚本,但由于某种原因,当我试图在文本视图中打印终端响应时,它们总是会出现奇怪的字符,而不是可读的ascii主动发送shell命令的函数是代码末尾的“PyPiCommands”。有人能解释一下,我用清晰的ASCII字符打印终端响应时遗漏了什么:

//The following method starts the initial ssh connection======================

public String executeRemoteCommand(String usrname, String passwd, String hostname, int Port) throws Exception {

    responseArray.add("Attempting to Connect...");
    Properties prop = new Properties();
    prop.put("StrictHostKeyChecking", "no");
    JSch jsch = new JSch();
    final Session session = jsch.getSession(usrname, hostname, Port);
    session.setPassword(passwd);
    session.setConfig(prop);
    session.connect();
    if (session.isConnected()) {
        piConnected = Boolean.TRUE;
    } else {
        responseArray.clear();
        Log.i("ssh", "Connection Failed");
        responseArray.add("Connection Failed.");
    }

    final ChannelExec channelssh = (ChannelExec) session.openChannel("exec");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    channelssh.setOutputStream(baos);
    channelssh.setOutputStream(baos);
    channelssh.setCommand(command);
    InputStream in = channelssh.getInputStream();
    channelssh.connect();

    if (channelssh.isConnected()) {
        System.out.println("channel connected");

        if (!channelssh.isClosed()) {
            System.out.println("channel not closed");
        }

        final BufferedReader bufferReader = new BufferedReader(new InputStreamReader(in));
        String result = bufferReader.readLine();
        for (int count = 0; count < result.length(); count++) {
            System.out.println("outstring: " + result);
            result = bufferReader.readLine();
            this.responseArray.add(count, result);
            if (result == null) {
                break;
            }
        }

        System.out.println("");
        System.out.println("response array: " + responseArray.toString());

        //channelssh.disconnect();
        //session.disconnect();

        final Channel channel = session.openChannel("shell");

        final OutputStream inputStream = channel.getOutputStream();
        final PrintStream commander = new PrintStream(inputStream, true);

        channel.setOutputStream(System.out, true);
        channel.connect();
        final String finalResult = result;
        final Runnable checkCommand = new Runnable() {
            @Override
            public void run() {
                try {
                    PyPiCommands(channel, command, inputStream, commander);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSchException e) {
                    e.printStackTrace();
                }
                if (sessKill == Boolean.FALSE) {
                    handler1.postDelayed(this, 200);
                }
            }
        };
        handler1.postDelayed(checkCommand, 300);

    }
    return responseArray.toString();

}
当我在监视器中打印指挥官数据时,我看到的是:

03-03 13:26:11.410 25133-25133/com.princton.litmo.prynsofpi I/System.out: printing rcv: java.io.PrintStream@d584d0a
但我知道它正在被接收,我只是不知道如何存储字符串并将其打印到应用程序的textview上,而不是上面的文本

03-03 13:26:11.740 25133-26877/com.app I/System.out: 5
03-03 13:26:11.740 25133-26877/com.app I/System.out: 5
03-03 13:26:11.740 25133-26877/com.app I/System.out: running
03-03 13:26:11.740 25133-26877/com.app I/System.out: straight
03-03 13:26:11.910 25133-26877/com.app I/System.out: Gimme dat: 

您已经发布了很多源代码,但没有多少关于您遇到的问题的信息。你应该把你的帖子简化成一个能证明你的问题的程序。您还应该包括您正在获得的实际输出和预期获得的输出的示例。@Kenster我已编辑了我的问题您发布了大量源代码,但关于您遇到的问题的信息不多。你应该把你的帖子简化成一个能证明你的问题的程序。您还应该包括您正在获得的实际输出和预期获得的输出的示例。@Kenster我已经编辑了我的问题
03-03 13:26:11.740 25133-26877/com.app I/System.out: 5
03-03 13:26:11.740 25133-26877/com.app I/System.out: 5
03-03 13:26:11.740 25133-26877/com.app I/System.out: running
03-03 13:26:11.740 25133-26877/com.app I/System.out: straight
03-03 13:26:11.910 25133-26877/com.app I/System.out: Gimme dat: