Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.IOException: Error running exec(). Commands: [cd, sdcard/.yasmin] Working Directory: null Environment: null

Tags:

android

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.

like image 607
lady android Avatar asked May 11 '11 11:05

lady android


3 Answers

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. 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.

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");

Or even better:

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

Hope it'll help!

like image 154
MByD Avatar answered Nov 15 '22 05:11

MByD


you should use Runtime.getRuntime().exec("sh -c cd /sdcard/.yasmin");

like image 44
user2507545 Avatar answered Nov 15 '22 05:11

user2507545


You can get the file generated with log as follows:

command - "your command" Environment - null Directory - null

Runtime.getRuntime().exec("your command",null,null);

like image 28
Gnanam R Avatar answered Nov 15 '22 05:11

Gnanam R