如何使用UNIX管道机器人 [英] How to use unix pipes in Android

查看:158
本文介绍了如何使用UNIX管道机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些数据,从我的应用程序在Android中发送给一个C程序,我想使用管道。我读了Java的可以利用现有的管道(并打开它们,就好像它是一个正常的文件) ,但我不能做这样的事情在我的应用程序。当我尝试,应用程序只是阻塞,直到等待消息接近出现,而无需编写任何特殊的logcat中。

I need to send some data to a C program from my app in Android, and I think about using pipes. I read that Java can access to existing pipes (and open them as if it's a normal file), but I'm unable to do such a thing in my application. When I try, the app just block until the message wait close appears, without writing anything special on logcat.

我发现了一个<一个href="http://groups.google.com/group/android-ndk/browse_thread/thread/943f95ecdc5ee72e/1736c4027d9af58c?pli=1">thread在Android邮件列表有关这个问题上,但它不是很清楚,它是指不上我的手机存在的文件夹。

I found a thread on android mailing lists about this subject, but it was not very clear, and it refers to a folder that does not exist on my phone.

此外,我知道这是不可能的SD卡做烟斗,但是当我尝试这样做, /数据,我想我有根的问题...你知道,如果有可能访问该管(Ⅰ在该应用文件夹的进出尝试没有成功)?

Furthermore, I know it's not possible to make pipes on the sdcard, but when I try to do so in/data, I think I have root issues… Do you know if it is possible to access to that pipe (I try in and out of the app folder without success)?

我用 mkfifo子所做的管道,和权限似乎确定是由所有用户开放。

I made the pipe with mkfifo, and the permissions seems OK to be open by any user.

prw-rw-rw- root     root              2010-11-18 04:53 video_pipe

我试图添加X权限(谁知道?)这里是我回:

I tried to add the X permission (who knows...) Here is what I have back:

# chmod u+x video_pipe 
Bad mode

在code表示块是相机初始化 PATH 只是路径管):

recorder.setOutputFile(PATH);

下面是整个源:<一href="https://github.com/rbochet/Simple-Camera-App/commits/piped">https://github.com/rbochet/Simple-Camera-App/commits/piped (提交<一个href="https://github.com/rbochet/Simple-Camera-App/commit/22dba257f6f68344cba6e1a0e147549d8693d5eb">22dba257f6)

Here is the whole source : https://github.com/rbochet/Simple-Camera-App/commits/piped (commit 22dba257f6)

感谢您的帮助

推荐答案

好吧,我试图用最笨的应用程序,存在解决这个问题。你可以发现这个为在github 的一个要点。

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 :

  • 在管道工程中唯一的地方是应用程序文件夹(即 /data/data/package.full.name /
  • 如果您希望将数据传递到另一个程序,你最好来运行它作为您的应用程序的孩子,以确保他们在同一个组,因此对该文件夹具有相同的授权。如果你不能,你也许可以用组(做的ls -l -a /数据/数据​​/ 键,看看组名)。
  • 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).

不要忘记:您不能其实写在管,直到有人在监听对方。所以,如果你考我贴在github上的文件,你就会有这样的logcat的结果。

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 started
W/ActivityManager(  220): Launch timeout has expired, giving up wake lock!
W/ActivityManager(  220): Activity idle timeout for HistoryRecord{4643c8b8 fr.stackr.android.upt/.UnixPipeActivity}

下面,系统暂停,因为没有任何反应......然后,我在手机上运行的猫v_pipe

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 :: Bip
V/UPIPE   ( 1359): Flushing...
V/UPIPE   ( 1359): SEND :: Bip post flush
V/UPIPE   ( 1359): Closing…
I/UPIPE   ( 1359): Attempt ended

这样做了。

关闭:当我关闭 OutputStreamWriter ,监听方(即 )结束。 如果我commment行,仍将等待输入。

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

刷新:好像是重要的,如果你的意图得到的东西,而不调用close

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

回车:使用

谢谢你的建议,我希望这将帮助别人。

Thank you for your advices, I hope this will help someone.

这篇关于如何使用UNIX管道机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆