Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old September 10th, 2010, 12:23 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Sep 2010
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Android Automation Script

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

Advertisements
CoopDeveloper is offline  
Last edited by CoopDeveloper; September 10th, 2010 at 12:24 AM. Reason: getting rid of the smiling faces
Reply With Quote
sponsored links
Old September 13th, 2010, 04:56 PM   #2 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,935
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 482 Times in 294 Posts
Default

Quote:
Originally Posted by CoopDeveloper View Post
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

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.
jonbonazza is offline  
Reply With Quote
Old September 15th, 2010, 05:05 AM   #3 (permalink)
New Member
 
Join Date: Sep 2010
Location: England
Posts: 4
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could try something in C++ maybe?

Code:
#include <iostream>
#include <unistd.h>
#include <time.h>

using namespace std;

int main()
{
    const char* command = "cmd_str"; // The command to be run
    pid_t pid;
    
    while(1)
    {
        for(time_t t = time(NULL) + 1200; time(NULL) < t;) {} // Wait for 1200 seconds (20 mins)
        pid = fork();
        if(pid == 0)
        {
            // in the child, do exec  
            execvp(command, NULL);
        }
        else if(pid != (pid_t) -1)
        {
            // in the parent, now perhaps do wait(pid)
        }
        else
        {
            // still in parent, but there is no child
        }
    }
}
This code will only work on a unix based system.
Change cmd_str to your desired command.
You need to compile it with:
Code:
g++ THEFILENAME.cpp -o looprun
And then run it with:
Code:
./looprun
I hope this helps.
Wolfy87 is offline  
Reply With Quote
Old September 20th, 2010, 06:53 PM   #4 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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..
hemk.rm is offline  
Reply With Quote
Reply
Tags
adb shell, adb shell script, android, automation, script


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:52 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.