本文介绍了java.io.IOException异常:EXEC运行错误()。命令:[CD,SD卡/ .yasmin]工作目录:空环境:空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试访问我的文件夹在SD卡并安装myapp.apk,我用这个code:

I try to access to my folder in sdcard and install myapp.apk, i use this code:

 Runtime.getRuntime().exec("cd sdcard/.yasmin");
 Runtime.getRuntime().exec("adb install tefli.apk");

但可惜的是,我有这个错误:

But unfortunatelly i have this error:

05-11 11:09:57.925: WARN/System.err(1399): java.io.IOException: 
Error running exec(). Commands: [cd, sdcard/.yasmin] Working Directory: null    Environment: null

请任何人有一个想法。在此先感谢。

Anybody please have an idea.thanks in advance.

推荐答案

我不知道,这将解决您的问题,但AFAIK,每次调用 EXEC()创建一个新的外壳。一个可能的解决方案是做到以下几点:

I am not sure that this will fix your problem, but AFAIK, each call to exec() creates a new shell. A possible solution is to do the following:

  1. 使用获取EXEC的过程():进程p =调用Runtime.getRuntime()EXEC(...)
  2. 使用 p.getInputStream()抓斗的过程中的InputStream;
  3. 运行第二个命令。
  1. Get the process of the exec() using: Process p = Runtime.getRuntime().exec(...).
  2. Grab the process inputStream using p.getInputStream();.
  3. Run the second command.

也注意到,您试图访问的SD卡作为你的根文件夹,并在硬codeD路径,考虑以下几点:

also note that you are trying to access the sdcard as you were in root folder and in a hardcoded path, consider the following:

Process p = Runtime.getRuntime().exec("cd /sdcard/.yasmin");

甚至更好:

Process p = Runtime.getRuntime().exec("cd " + Environment.getExternalStorageDirectory() + "/.yasmin");

希望能对大家有所帮助!

Hope it'll help!

这篇关于java.io.IOException异常:EXEC运行错误()。命令:[CD,SD卡/ .yasmin]工作目录:空环境:空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:40