Search code examples
androidprocesssqliteexitstatus

RunTime.exec does not return errors from the process


I have to develop an app that reads messages from whatsapp database.

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void sendMessage(View view){
        try{
            Process p = Runtime.getRuntime.exec(new String[] {"sqlite3", 
                "/data/data/com.whatsapp/databases/msgstore.db", 
                "select * from messages;"});
        }
        catch(Exception e){
            textView4.setText(e.getMessage());
        }
    }
}

Only when I make mistake with sqlite3(e.g. sqlite34 in stead of sqlite3), an error comes. But when I make mistakes in the other statements(e.g. databs in stead of databases), no error come. This means exec fires only the first statement, the other two statements would not be fired.


Solution

  • exec() succeeds when it has managed to started that process.

    To find out the return value of the sqlite3 process, you have to use the Process object to wait for it to end, and then to read its exit value.