0

I have the .sh file inside the raw folder, I tried by using this code. but it always said no file found or directory.

public void onClick(View arg0) {
  Log.d("hello", "dasdasd");
  String uriPath = "android.resource://" + getPackageName() + "/raw/on.sh";
  Uri uri = Uri.parse(uriPath);
  Process p = null;
  try {
    p = new ProcessBuilder()
      .command(uriPath)
      .start();
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    if (p != null) p.destroy();
  }
}

File or directory not found

shrys
  • 5,860
  • 2
  • 21
  • 36
Amjad Mehmood
  • 245
  • 1
  • 5
  • 14

1 Answers1

0

you can run your commands through your code using Runtime class or copy your file to internalStorage then run it.

Runtime.getRuntime().exec("path_to_file/raw/on.sh");

you can run your commands like this and put it's output in variable.

Process output = Runtime.getRuntime().exec("your command");

then get inputstream from it.

InputStream inputStream = output.getInputStram();