1. Check out our app, Forums for Android! Download and leave feedback here!

Android Automation Script

Discussion in 'Application Development' started by CoopDeveloper, Sep 10, 2010.

  1. CoopDeveloper

    CoopDeveloper New Member
    Thread Starter
    5

    Sep 10, 2010
    1
    0
    5
    Hi guys, i need to automate the following process but i do not know how, any tip on creating this is appreciated.

    in ADB SHELL, (say the command I want to execute is cmd_str)

    pseudocode:

    cmd_str
    execute cmd_str every 20 minutes

    how can i write a script that can be run in adb shell that does the above?

    if what i wrote above is not clear, here it is again


    for ( ; ; ) {
    execute cmd_str;
    sleep(20)
    }

    please help thank you
     

    Advertisement

  2. jonbonazza

    jonbonazza Well-Known Member
    163

    Jul 13, 2010
    1,934
    458
    163
    Male

    Shell language is NOT a programming language. it is a command line language, therefore you cannot execute things like loops, etc... It is meant to execute commands one line at a time (hence the name command line). Unfortunately, there is no way to do what you want automatically.
     
  3. Wolfy87

    Wolfy87 New Member
    25

    Sep 14, 2010
    4
    0
    25
    Junior Web Developer
    England
    You could try something in C++ maybe?

    Code (Text):
    1.  
    2. #include <iostream>
    3. #include <unistd.h>
    4. #include <time.h>
    5.  
    6. using namespace std;
    7.  
    8. int main()
    9. {
    10.     const char* command = "cmd_str"; // The command to be run
    11.     pid_t pid;
    12.    
    13.     while(1)
    14.     {
    15.         for(time_t t = time(NULL) + 1200; time(NULL) < t;) {} // Wait for 1200 seconds (20 mins)
    16.         pid = fork();
    17.         if(pid == 0)
    18.         {
    19.             // in the child, do exec  
    20.             execvp(command, NULL);
    21.         }
    22.         else if(pid != (pid_t) -1)
    23.         {
    24.             // in the parent, now perhaps do wait(pid)
    25.         }
    26.         else
    27.         {
    28.             // still in parent, but there is no child
    29.         }
    30.     }
    31. }
    32.  
    This code will only work on a unix based system.
    Change cmd_str to your desired command.
    You need to compile it with:
    Code (Text):
    1. g++ THEFILENAME.cpp -o looprun
    And then run it with:
    Code (Text):
    1. ./looprun
    I hope this helps.
     
  4. hemk.rm

    hemk.rm New Member
    5

    Sep 20, 2010
    1
    0
    5
    If there is no hard requirement, for you to run the script in the adb shell prompt, then you can just write a perl script and execute it on the windows.

    Basically, you are running ur perl script on windows machine. Your windows machine and device are connected using an usb cable.
    You can write, what ever you want in the perl script.
    You can invoke an adb command as system("adb shell ls "), so forth..
     

Share This Page

Loading...