No Output with DataInputStream

0

I'm trying to build an application that works as a terminal emulator, but simply no output is generated.

Here's my code, it might be useful:

package me.craftygaming.TermDroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import me.craftygaming.TermDroid.R;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;

/**
 * Created by ********* on 11/01/17.
 */
public class ActivityTerminal extends Activity {
    TextView console;
    EditText cmd;
    DataOutputStream os;
    DataInputStream is;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.Activityterminal);
        Intent intent = getIntent();
        String message = intent.getStringExtra("me.craftygaming.TDroid.MODE");
        String args = intent.getStringExtra("me.craftygaming.TDroid.ARGS");
        File f = new File(message);
        File term = new File(f, "system/bin/python");

        System.out.println(f.getAbsolutePath());
        console = (TextView)findViewById(R.id.console);
        cmd = (EditText)findViewById(R.id.command);

        try {
            Process p = Runtime.getRuntime().exec("/system/bin/sh -");
            os = new DataOutputStream(p.getOutputStream());
            is = new DataInputStream(p.getInputStream());

            os.writeBytes(term.getCanonicalPath()+"\n");
            os.writeBytes("echo \"Hi\"\n");
        }catch(IOException ex){}
        updater.start();

    }
    public void Submit(View view){
        try{
      String comand = cmd.getText().toString();
        os.writeBytes(comand);
            console.append("\n>> "+comand+"\n");
            cmd.setText("");
            } catch (IOException e){

                CharSequence text = "Error! "+e.getLocalizedMessage();
                int duration = Toast.LENGTH_LONG;

                Toast toast = Toast.makeText(getApplicationContext(), text, duration);
                toast.show();
            }
    }
    Thread updater = new Thread() {
        @Override
        public void run() {
            while(true){
                try {
                    while (is.available() == 0) {
                    }
                    console.append(is.readUTF() + "\n");
                }catch(IOException e){
                    console.append("ERROR READING!");
                }
            }

        }
    };
}

In addition, is there any better way to get data from DataInputStream ?

    
asked by anonymous 11.01.2017 / 08:22

0 answers