How to use unix pipes in Android How to use unix pipes in Android unix unix

How to use unix pipes in Android


Ok, I tried to fix the problem with the most stupid app that exists. You can find this one as a gist on github.

So far, I discover this :

  • The only place where the pipe works is the app folder (ie /data/data/package.full.name/)
  • If you want to pass data to another program, you had better to launch it as a child of your app to ensure they are in the same group and thus have the same authorisation for the folder. If you can't, you might be able to play with the groups (do ls -l -a on /data/data/ and have a look to the group name).

DO NOT FORGET : You can't actually write in the pipe until someone is listening at the other side. So if you test the file I posted on github, you will have that kind of logcat result.

I/ActivityManager(  220): Start proc fr.stackr.android.upt for activity fr.stackr.android.upt/.UnixPipeActivity: pid=1359 uid=10048 gids={}I/UPIPE   ( 1359): Attempt startedW/ActivityManager(  220): Launch timeout has expired, giving up wake lock!W/ActivityManager(  220): Activity idle timeout for HistoryRecord{4643c8b8 fr.stackr.android.upt/.UnixPipeActivity}

Here, the system pause because nothing happens… Then I run cat v_pipe on the phone.

V/UPIPE   ( 1359): SEND :: Try to write the first paragraph ....V/UPIPE   ( 1359): SEND :: BipV/UPIPE   ( 1359): Flushing...V/UPIPE   ( 1359): SEND :: Bip post flushV/UPIPE   ( 1359): Closing…I/UPIPE   ( 1359): Attempt ended

That's done.

closing : when I close the OutputStreamWriter, the listening side (ie cat) ends.If I commment the line, cat will still wait for input.

flushing : seems to be important if you intent to get something without calling close.

Carriage Return : Use \n.


I think you can use ParcelFileDescriptor.createPipe()

It will return an array of pipe for read and write. For more information, visit the developers website.