0

Cannot solve this

I have tried everything I could find

 try {
            process = Runtime.getRuntime().exec("chmod -777 YourAndroidStudioFolder"+
            "chmod +x /User/Library/Android/sdk/build-tools/23.0.1/aapt\\n\" +\n" +
                    "                        \"chmod +x /User/Library/Android/sdk/build-tools/23.0.1/dx\\n\" +\n" +
                    "                        \"chmod +x /User/Library/Android/sdk/build-tools/23.0.1/zipalign"+"cat config.cpp");
            dataOutputStream = new DataOutputStream(process.getOutputStream());
            //dataOutputStream.writeBytes("g++ config.cpp -o a.out");
            //dataOutputStream.writeBytes("exit\n");
            dataOutputStream.flush();
            process.waitFor();
            Log.v("SUccess", "works");
        } catch (Exception e) {
            Log.v("Error:",e.toString());
        } finally {
            try {
                if (dataOutputStream != null) {
                    dataOutputStream.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }

This code works but

process = Runtime.getRuntime().exec("g++ config.cpp -o a.out");

This does not work keeps getting error13.

Johan
  • 3,667
  • 6
  • 20
  • 25
dusrud
  • 33
  • 4

1 Answers1

0

Try to check which g++ you are actually trying to use and check permissions.

 ls -l `which g++`
frumle
  • 593
  • 5
  • 15
  • what do you mean which g++? – dusrud Jan 31 '19 at 15:48
  • I suppose that everything is ok with your sources but you have no permissions to execute compiler program. Try to execute the command I mentioned from your Java code and read the output. (The first part: 'which g++' will show you the exact file of g++ executable you're trying to run and the second one will show you either you have permission to execute g++ or not.) – frumle Jan 31 '19 at 15:56
  • I have given all permission with chmod777 and have checked with ls -l. It shows -rwxrwxrwx. But compile command is still denied permission – dusrud Jan 31 '19 at 15:59
  • Yes, right. Let's consider the command which throws an exception: `g++ config.cpp -o a.out`. What does this command do? It runs the program `g++` with some options and arguments. The problem is that it is no mater if you have rw permissions to your own files (your sources) if you have no permission to execure `g++` program. – frumle Jan 31 '19 at 16:18
  • Oh I got it. I tried which g++, and nothing shows. What does this mean? – dusrud Jan 31 '19 at 16:26
  • I have just edited the command in the answer, previous one was wrong.. Sorry :) – frumle Jan 31 '19 at 16:32
  • That's okay i've just tried the edited command and i still get blank. Maybe gcc isn't installed on my phone? I thought i wouldn't have to install it am i wrong? – dusrud Jan 31 '19 at 16:37
  • How did you get an output when run this command? It seems that you just only run the command. – frumle Jan 31 '19 at 16:53
  • I tried that command on my computer and it shows /usr/bin/g++. But on my phone where I am supposed to use this, output is nothing. – dusrud Jan 31 '19 at 17:04
  • I was expect that `GCC` is not included in Android from the box. But it is strange for me that you're getting exactly this exception: `error=13, Permission denied` in this case. – frumle Jan 31 '19 at 17:26
  • Try to run this `Runtime.getRuntime().exec("g++ --help");`, for example, instead of `Runtime.getRuntime().exec("g++ config.cpp -o a.out");`, and get an output in [this way](https://stackoverflow.com/a/5711150/5531164). – frumle Jan 31 '19 at 17:35
  • "g++ --help" still gets the same error . Caused by: java.lang.RuntimeException: java.io.IOException: Cannot run program "g++": error=13, Permission denied :( – dusrud Feb 01 '19 at 03:39
  • I tried to run this command on my device and got the same error. But I still getting the same error on Android even when trying to run `Runtime.getRuntime().exec("someNonexistentBinary");`. I tried also the last command with pure Java on my laptop (Debian dist.) and got another exception: `Cannot run program "nonexistentExecutable": error=2, No such file or directory`. I would also expect to get error 2 instead of 13 on Android and really don't know why it throws error=13 instead. – frumle Feb 01 '19 at 07:31
  • I have come to the conclusion that this is impossible, unless i root my phone. – dusrud Feb 12 '19 at 15:21