Android 错误:写入失败:EPIPE (Broken pipe)

Posted

技术标签:

【中文标题】Android 错误:写入失败:EPIPE (Broken pipe)【英文标题】:Android error: write failed: EPIPE (Broken pipe) 【发布时间】:2017-07-19 14:39:40 【问题描述】:

我正在尝试使用以下命令在 android 中执行需要 root 访问权限的命令:

public static void runCmd(String cmd) 
        DataOutputStream os;
        try 
            Process process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            //os.writeBytes(cmd + "\n");
            os.writeBytes("echo hello\n");    <---- This fails?
            os.writeBytes("exit\n");
            os.flush();
            os.close();
         catch (IOException e) 
            e.printStackTrace();
        
    

如您所见,我已将实际命令注释掉,以排除它与 root 访问权限有关(“echo hello”不需要 root 权限吗?)。我在 Android 4.2 设备上使用了很多代码,现在我们必须使用 Android 4.4,它不再工作了。我得到错误:

07-19 22:29:29.555 20744-20744/? W/System.err: java.io.IOException: write failed: EPIPE (Broken pipe)
07-19 22:29:29.555 20744-20744/? W/System.err:     at libcore.io.IoBridge.write(IoBridge.java:455)
07-19 22:29:29.555 20744-20744/? W/System.err:     at java.io.FileOutputStream.write(FileOutputStream.java:187)
07-19 22:29:29.555 20744-20744/? W/System.err:     at java.io.OutputStream.write(OutputStream.java:82)
07-19 22:29:29.555 20744-20744/? W/System.err:     at java.io.DataOutputStream.writeBytes(DataOutputStream.java:156)
07-19 22:29:29.555 20744-20744/? W/System.err:     at com.company.kioskapp.MainActivity.runCmd(MainActivity.java:298)
07-19 22:29:29.555 20744-20744/? W/System.err:     at com.benefittechnologies.benekiosk.MainActivity.disableAndroidUI(MainActivity.java:273)
07-19 22:29:29.555 20744-20744/? W/System.err:     at com.benefittechnologies.benekiosk.MainActivity.onCreate(MainActivity.java:124)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.app.Activity.performCreate(Activity.java:5254)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.os.Looper.loop(Looper.java:136)
07-19 22:29:29.555 20744-20744/? W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5001)
07-19 22:29:29.555 20744-20744/? W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
07-19 22:29:29.555 20744-20744/? W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
07-19 22:29:29.555 20744-20744/? W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
07-19 22:29:29.555 20744-20744/? W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:617)
07-19 22:29:29.555 20744-20744/? W/System.err:     at dalvik.system.NativeStart.main(Native Method)
07-19 22:29:29.555 20744-20744/? W/System.err: Caused by: libcore.io.ErrnoException: write failed: EPIPE (Broken pipe)
07-19 22:29:29.555 20744-20744/? W/System.err:     at libcore.io.Posix.writeBytes(Native Method)
07-19 22:29:29.555 20744-20744/? W/System.err:     at libcore.io.Posix.write(Posix.java:202)
07-19 22:29:29.555 20744-20744/? W/System.err:     at libcore.io.BlockGuardOs.write(BlockGuardOs.java:197)
07-19 22:29:29.555 20744-20744/? W/System.err:     at libcore.io.IoBridge.write(IoBridge.java:450)
07-19 22:29:29.555 20744-20744/? W/System.err:  ... 20 more 

如果我注释掉

os.writeBytes("echo hello\n");

行也是如此,没有例外。

【问题讨论】:

你有什么解决办法吗?? 【参考方案1】:

事实证明,这实际上是一个根本错误。设备未正确植根。查看我的其他帖子:How to check if custom android is rooted?

【讨论】:

以上是关于Android 错误:写入失败:EPIPE (Broken pipe)的主要内容,如果未能解决你的问题,请参考以下文章

Node.js - 我不断收到以下错误:错误:ffmpeg 流:写入 EPIPE

NodeJS - 错误:在 SOCKS5 代理上写入 EPIPE

使用 node-pdftk 填写表单时写入 EPIPE 错误

流星 EPIPE 错误中的 html-pdf

ExtAudioRecorder:“写入失败:EBADF(错误文件描述符)”将音频录制到 WAV 文件 - Android Studio

损坏管道上的发送行为