Android StdInput and StdOutput to native process
<p>Here is some code that doesn't work. I think it should and was hoping someone could tell me why it doesn't.
It started out to be one thing and then grew into this which didn't work. Now its become kind of a challenge.
Basically it starts the sh shell program and attempts to send commands to it and get back the results.
It works fine, once. The second time, it stops at writer.close() as if its already closed and I think it is!
It it doesn't have the close() it hangs waiting for something to happen. I guess for it to close?
I have tried flush() and newline() but they didn't seem to help. 
I have tried it in the emulator and also on a phone. Same results.</p>

<pre><code>@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    body = (EditText)findViewById(R.id.bodyEditText);
    body.setOnEditorActionListener(mSendListener);
    try {
    // Start the shell and save the process id  
    process = Runtime.getRuntime().exec("/system/bin/sh");  
    } 
    catch (IOException e) {
        body.append("Shell Error\n$ ");
        e.printStackTrace();
        }
    }//oncreate

public void shellExec(String cmd) {
    try {
    // Create a writer for the standard input to the shell
    // and write the command    
    BufferedWriter writer = new BufferedWriter(
        new OutputStreamWriter(process.getOutputStream()));
    writer.write(cmd+"\n");
    writer.close();
    // Create a reader for the standard output of the shell
    // and read the result  
    BufferedReader reader = new BufferedReader(
        new InputStreamReader(process.getInputStream()));
    int i;
    char[] buffer = new char[4096];
    StringBuffer output = new StringBuffer();
    while ((i = reader.read(buffer)) &gt; 0) output.append(buffer, 0, i);
    reader.close();
    // Add the result to the EditText text
    body.append(output.toString()+"\n$ ");
    } 
    catch (IOException e) {
        body.append(cmd+" Error"+"\n$ ");
        }
    }//shellexec
</code></pre>
