安卓:写失败:EPIPE(管道中断)错误上写文件上写、管道、错误、文件

2023-09-13 00:28:23 作者:ヅ无聊先生

我试图采取了Android屏幕截图编程。我做了以下code:

 私人无效getsnap(){
    尝试{
        过程SH =调用Runtime.getRuntime()EXEC(素,NULL,NULL);
        OutputStream的OS = sh.getOutputStream();
        字符串文件路径= this.getFilesDir()getPath()的toString()+/fileName1.jpeg。
        os.write((/系统/斌/ screencap -p+文件路径).getBytes(ASCII));
        os.flush();
        os.close();
        sh.waitFor();
    }
    赶上(例外五)
    {
        e.printStackTrace();
    }
}
 

  

java.io.IOException异常:写失败:EPIPE(断管)

请能有人帮忙吗?我已经检查了其他职位,我不找到任何解决我的问题。

编辑:

SolidWorks 技术交流区对学习ROUTING中PIPE管道的问题我们知道SW中的ROUTING插件管道有PIPR和TUBE,对于TUBU主要是可弯曲的非金属管道,而PIPE则一般是金属管道,在设计中我最大的疑问是

请注意,错误发生在该行 os.write()

解决方案

EPIPE问题通常是因为你要么尝试执行命令,需要root权限( getRuntime()。EXEC )你的情况没有在设备上或者同时运行几个根命令。如果您在模拟器上工作,需要铲除它,我想你的模拟器运行时,你可以试试这个:

 亚行外壳安装邻RW,重新挂载-t YAFFS2的/ dev /块/ mtdblock03 /系统
亚行推动苏/系统/ XBIN /苏
亚行外壳搭配chmod 06755 /系统
亚行外壳搭配chmod 06755 /系统/ XBIN /苏
 

在这里http://abd-tech.blogspot.com/2011/05/test-root-apps-on-android-emulator.html更详细的解释。

I was trying to take screenshot of the Android screen programatically. I had done the following code:

private void getsnap(){
    try{
        Process sh = Runtime.getRuntime().exec("su", null, null);
        OutputStream os = sh.getOutputStream();
        String filePath = this.getFilesDir().getPath().toString() + "/fileName1.jpeg";
        os.write(("/system/bin/screencap -p " + filePath).getBytes("ASCII"));
        os.flush();
        os.close();
        sh.waitFor();       
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}

java.io.IOException: write failed: EPIPE (Broken pipe)

Please can someone help? I had already checked the other posts and I dont find anything solving my issue.

EDIT:

Please note, the Error happens in the line os.write().

解决方案

EPIPE issue usually happens when you either try to execute command which needs root permissions (getRuntime().exec) in your case on the device without it or run several root commands simultaneously. If you work on the emulator and need to root it I think you you can try this while the emulator is running:

adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system  
adb push su /system/xbin/su  
adb shell chmod 06755 /system  
adb shell chmod 06755 /system/xbin/su

Here http://abd-tech.blogspot.com/2011/05/test-root-apps-on-android-emulator.html more detail explanation.