A
A
Alex2016-11-11 13:25:25
Android
Alex, 2016-11-11 13:25:25

Why doesn't exec work?

I have code:

String[] cmd = new String[] {"su", "./php lol.php"}; 
Runtime.getRuntime().exec(cmd);

The php file has rwx rights, in the terminal emulator for Android php the script was executed with a bang, but not in the application.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aol-nnov, 2016-11-11
@aol-nnov

su do you have on your phone, of course? :)

Z
zhekazt, 2016-11-11
@zhekazt

try {
            Process process = Runtime.getRuntime().exec("./php lol.php");
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));
            int read;
            char[] buffer = new char[4096];
            StringBuffer output = new StringBuffer();
            while ((read = reader.read(buffer)) > 0) {
                output.append(buffer, 0, read);
            }
            reader.close();
            process.waitFor();
            return output.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

and check that .your paths are correct

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question