Execute file from Android device programatically












0















I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:



try {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String path = f.getAbsolutePath();
String stockfishPath = path + "/Stockfish-9-armv64v8";
engineProcess = Runtime.getRuntime().exec(stockfishPath);
processReader = new BufferedReader(new InputStreamReader(
engineProcess.getInputStream()));

String sCurrentLine;

ArrayList<String> output = new ArrayList<>();
while ((sCurrentLine = processReader.readLine()) != null) {
output.add(sCurrentLine);
}

processWriter = new OutputStreamWriter(
engineProcess.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}


When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).



Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?










share|improve this question





























    0















    I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:



    try {
    File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    String path = f.getAbsolutePath();
    String stockfishPath = path + "/Stockfish-9-armv64v8";
    engineProcess = Runtime.getRuntime().exec(stockfishPath);
    processReader = new BufferedReader(new InputStreamReader(
    engineProcess.getInputStream()));

    String sCurrentLine;

    ArrayList<String> output = new ArrayList<>();
    while ((sCurrentLine = processReader.readLine()) != null) {
    output.add(sCurrentLine);
    }

    processWriter = new OutputStreamWriter(
    engineProcess.getOutputStream());
    } catch (Exception e) {
    e.printStackTrace();
    }


    When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).



    Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?










    share|improve this question



























      0












      0








      0








      I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:



      try {
      File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
      String path = f.getAbsolutePath();
      String stockfishPath = path + "/Stockfish-9-armv64v8";
      engineProcess = Runtime.getRuntime().exec(stockfishPath);
      processReader = new BufferedReader(new InputStreamReader(
      engineProcess.getInputStream()));

      String sCurrentLine;

      ArrayList<String> output = new ArrayList<>();
      while ((sCurrentLine = processReader.readLine()) != null) {
      output.add(sCurrentLine);
      }

      processWriter = new OutputStreamWriter(
      engineProcess.getOutputStream());
      } catch (Exception e) {
      e.printStackTrace();
      }


      When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).



      Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?










      share|improve this question
















      I have finished my Chess UI application and now want to load a chess engine to test if my UI truly is UCI-compatible. The chess engine is inside the Download folder of the Android device ('/storage/emulated/0/Download'). This is the code that is run:



      try {
      File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
      String path = f.getAbsolutePath();
      String stockfishPath = path + "/Stockfish-9-armv64v8";
      engineProcess = Runtime.getRuntime().exec(stockfishPath);
      processReader = new BufferedReader(new InputStreamReader(
      engineProcess.getInputStream()));

      String sCurrentLine;

      ArrayList<String> output = new ArrayList<>();
      while ((sCurrentLine = processReader.readLine()) != null) {
      output.add(sCurrentLine);
      }

      processWriter = new OutputStreamWriter(
      engineProcess.getOutputStream());
      } catch (Exception e) {
      e.printStackTrace();
      }


      When I run this it fails on the exec() method because it claims it cannot find the file, even though the file exists on the Android device. I tried running the "ls" command on the exec() method, but the folder inside "emulated" is empty. The obvious reason for this is probably because I do not have permission to view/access these files, but I need to know how I can do that (despite adding the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE in the manifest file).



      Is it maybe possible to embed the engine somewhere in the project (in resources?) and somehow adb-shell into that?







      java android file






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 0:30







      DanZoe

















      asked Nov 21 '18 at 23:38









      DanZoeDanZoe

      3129




      3129
























          1 Answer
          1






          active

          oldest

          votes


















          0














          you cannot do that, simply because the SD card is being mounted with -noexec flag.



          using the internal storage with chmod +x would be the only option available.






          share|improve this answer
























          • It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?

            – DanZoe
            Nov 22 '18 at 0:16













          • @DanZoe this is not the internal storage; just see how often you've used the word external above. use getFilesDir().getAbsolutePath() and .exec("chmod +x " + stockfishPath). while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage command available to label the file.

            – Martin Zeitler
            Nov 22 '18 at 1:29













          • I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?

            – DanZoe
            Nov 22 '18 at 5:03











          • @DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.

            – Martin Zeitler
            Nov 22 '18 at 6:32













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421962%2fexecute-file-from-android-device-programatically%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          you cannot do that, simply because the SD card is being mounted with -noexec flag.



          using the internal storage with chmod +x would be the only option available.






          share|improve this answer
























          • It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?

            – DanZoe
            Nov 22 '18 at 0:16













          • @DanZoe this is not the internal storage; just see how often you've used the word external above. use getFilesDir().getAbsolutePath() and .exec("chmod +x " + stockfishPath). while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage command available to label the file.

            – Martin Zeitler
            Nov 22 '18 at 1:29













          • I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?

            – DanZoe
            Nov 22 '18 at 5:03











          • @DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.

            – Martin Zeitler
            Nov 22 '18 at 6:32


















          0














          you cannot do that, simply because the SD card is being mounted with -noexec flag.



          using the internal storage with chmod +x would be the only option available.






          share|improve this answer
























          • It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?

            – DanZoe
            Nov 22 '18 at 0:16













          • @DanZoe this is not the internal storage; just see how often you've used the word external above. use getFilesDir().getAbsolutePath() and .exec("chmod +x " + stockfishPath). while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage command available to label the file.

            – Martin Zeitler
            Nov 22 '18 at 1:29













          • I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?

            – DanZoe
            Nov 22 '18 at 5:03











          • @DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.

            – Martin Zeitler
            Nov 22 '18 at 6:32
















          0












          0








          0







          you cannot do that, simply because the SD card is being mounted with -noexec flag.



          using the internal storage with chmod +x would be the only option available.






          share|improve this answer













          you cannot do that, simply because the SD card is being mounted with -noexec flag.



          using the internal storage with chmod +x would be the only option available.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 0:15









          Martin ZeitlerMartin Zeitler

          15.6k33965




          15.6k33965













          • It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?

            – DanZoe
            Nov 22 '18 at 0:16













          • @DanZoe this is not the internal storage; just see how often you've used the word external above. use getFilesDir().getAbsolutePath() and .exec("chmod +x " + stockfishPath). while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage command available to label the file.

            – Martin Zeitler
            Nov 22 '18 at 1:29













          • I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?

            – DanZoe
            Nov 22 '18 at 5:03











          • @DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.

            – Martin Zeitler
            Nov 22 '18 at 6:32





















          • It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?

            – DanZoe
            Nov 22 '18 at 0:16













          • @DanZoe this is not the internal storage; just see how often you've used the word external above. use getFilesDir().getAbsolutePath() and .exec("chmod +x " + stockfishPath). while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage command available to label the file.

            – Martin Zeitler
            Nov 22 '18 at 1:29













          • I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?

            – DanZoe
            Nov 22 '18 at 5:03











          • @DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.

            – Martin Zeitler
            Nov 22 '18 at 6:32



















          It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?

          – DanZoe
          Nov 22 '18 at 0:16







          It is internal storage. There is no SD-card. Could you give and example with the chmod +x with the exec method specified?

          – DanZoe
          Nov 22 '18 at 0:16















          @DanZoe this is not the internal storage; just see how often you've used the word external above. use getFilesDir().getAbsolutePath() and .exec("chmod +x " + stockfishPath). while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage command available to label the file.

          – Martin Zeitler
          Nov 22 '18 at 1:29







          @DanZoe this is not the internal storage; just see how often you've used the word external above. use getFilesDir().getAbsolutePath() and .exec("chmod +x " + stockfishPath). while it possibly might not run without root, because the SE Linux labels could prevent it from doing so - and unless being root, there is no semanage command available to label the file.

          – Martin Zeitler
          Nov 22 '18 at 1:29















          I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?

          – DanZoe
          Nov 22 '18 at 5:03





          I see. Is there another way of executing the stockfish executable. I have searched and searched, and the only thing I need, is to actually execute it, no matter the location. Do you have any tips?

          – DanZoe
          Nov 22 '18 at 5:03













          @DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.

          – Martin Zeitler
          Nov 22 '18 at 6:32







          @DanZoe have you tried the suggested method yet? "I see" does not exactly sound alike.

          – Martin Zeitler
          Nov 22 '18 at 6:32




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421962%2fexecute-file-from-android-device-programatically%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin