title: How to get results from SQLite3 query in Android using root
body: <p>I'm trying to access a database using root and sqlite3 to get data from it.</p>
  
  <p>So far I managed to display data in the logcat but I can't get it in a file or any other way.</p>
  
  <p>Using <a href="https://github.com/Free-Software-for-Android/RootCommands" rel="nofollow noreferrer">RootCommand library</a>  this is my code :</p>
  
  <pre><code>public void readDB(String message){
      try {
          Shell shell = Shell.startRootShell();
          String setOutput= "sqlite3 .output /sdcard/number.txt"; // This didn't work because it treats .output as a database name
          String readTest = "sqlite3  /data/data/com.package/databases/someDB.db \"SELECT * FROM table\";";
  
          shell.add(new SimpleCommand(setOutput)).waitForFinish();
          shell.add(new SimpleCommand(readTest)).waitForFinish();
          Log.d(TAG , "finished");
      } catch (IOException | TimeoutException e) {
          e.printStackTrace();
          Log.e(TAG, e.getMessage());
      }
  }
  </code></pre>
  
  <p>As explained <a href="http://www.sqlite.org/cli.html" rel="nofollow noreferrer">here</a>  I used <code>.output</code> to specify a file but it didn't work because it treats <code>.output</code> as a database name and throws an exception that it can't find the db and continues to display results in logcat.</p>
  
  <p>And I tried <code>writefile('/sdcard/myfile.txt',column)</code> but no file and no data in logcat.</p>
  
  <p>When I try <code>.output /sdcard/myfile.txt</code> from adb it works fine and I find the results in the file but I can't get it done through the code</p>
  
  <p>So how to get this data in anyway? Is there any better approach to do this?</p>
  
  <p>PS: I'm not accessing my own app data so I can't use sqlite database helper class.</p>