[java] Shell Script starten op Android

Pagina: 1
Acties:
  • 421 views

Onderwerpen


Acties:
  • 0 Henk 'm!

  • ObAt
  • Registratie: Januari 2009
  • Laatst online: 06-06 08:09

ObAt

Loading...

Topicstarter
Hallo Tweakers,

Ik wil graag een shell script starten vanuit mijn Android Application. Het shell script staat in '/data/chmod.sh' op mijn gerootte Galaxy Tab en staat chmod '777. Ik snap niet waarom dit niet werkt.

Java:
1
Runtime.getRuntime().exec("sh /data/chmod.sh");


Of deze code:

Java:
1
2
3
4
5
6
7
8
p = Runtime.getRuntime().exec("sh /data/chmod.sh");

            try {  
                     p.waitFor();
                 } catch (InterruptedException e1) {
                 Toast.makeText(v.getContext(), (CharSequence) e1,
                            Toast.LENGTH_LONG).show();
             }


Dit is de code van chmod.sh

code:
1
2
3
su
/system/bin/chmod 777 /data/.nvmac.info
/system/bin/chmod 777 /data/.mac.info


Kan iemand mij helpen?

Alvast bedankt

[ Voor 9% gewijzigd door ObAt op 05-05-2012 14:40 ]

Mijn dagelijkse spamdosis is te lezen op http://twitter.com/#!/ObAtG


Acties:
  • 0 Henk 'm!

  • Wirf
  • Registratie: April 2000
  • Laatst online: 26-06 08:38
Misschien moet je de parameter ("/data/chmod.sh" in jouw geval) opgeven als parameter?

zoiets:
Java:
1
Runtime.getRuntime().exec("/bin/sh", "/data/chmod.sh");

Heeft sinds kort zijn wachtwoord weer terug gevonden!


Acties:
  • 0 Henk 'm!

  • ObAt
  • Registratie: Januari 2009
  • Laatst online: 06-06 08:09

ObAt

Loading...

Topicstarter
Dit werkt niet, Eclipse geeft al standaard een error aan.

Java:
1
Runtime.getRuntime().exec("/bin/sh", "/data/chmod.sh");


Deze lijn geeft geen error aan:

Java:
1
Runtime.getRuntime().exec("/bin/sh /data/chmod.sh");


Maar de app crasht op mijn Tablet. Dit is trouwens de chmod.sh:

code:
1
2
3
su
/system/bin/chmod 777 /data/.nvmac.info
/system/bin/chmod 777 /data/.mac.info

Mijn dagelijkse spamdosis is te lezen op http://twitter.com/#!/ObAtG


Acties:
  • 0 Henk 'm!

  • ObAt
  • Registratie: Januari 2009
  • Laatst online: 06-06 08:09

ObAt

Loading...

Topicstarter
Antwoord is te vinden op Stackoverflow. Hiermee kun je de shell commands gewoon een voor een uitvoeren.

Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void execCommandLine(String command)
    {
        Runtime runtime = Runtime.getRuntime();
        Process proc = null;
        OutputStreamWriter osw = null;

        try
        {
            proc = runtime.exec("su");
            osw = new OutputStreamWriter(proc.getOutputStream());
            osw.write(command);
            osw.flush();
            osw.close();
        }
        catch (IOException ex)
        {
            Log.e("execCommandLine()", "Command resulted in an IO Exception: " + command);
            return;
        }
        finally
        {
            if (osw != null)
            {
                try
                {
                    osw.close();
                }
                catch (IOException e){}
            }
        }

        try 
        {
            proc.waitFor();
        }
        catch (InterruptedException e){}

        if (proc.exitValue() != 0)
        {
            Log.e("execCommandLine()", "Command returned error: " + command + "\n  Exit code: " + proc.exitValue());
        }
    }

Mijn dagelijkse spamdosis is te lezen op http://twitter.com/#!/ObAtG


Acties:
  • 0 Henk 'm!

  • Creepy
  • Registratie: Juni 2001
  • Nu online

Creepy

Tactical Espionage Splatterer

En 1 topic is wel genoeg vind je niet ;)

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Dit topic is gesloten.