Running a script from a script in android - android

i am trying to use an init.d script to execute another script in the background. The init.d script must continue immediatly after executing the other script in the background so my device can boot completely and then the executed script can do its commands. I have googled and found that the & symbol can be used at the end of the script name to execute it in the background. This worked, but my init.d script waited until the background script was finished. So i googled some more, and found that nohup command in use with & will do what i want. Perfect. HOWEVER when i used terminal emulator on android, i typed, nohup and i get "nohup: applet not found"
So as above i have no way of continuing the init.d script without it waiting for the background script. I am asking, Does anyone know how to run a script in the background while continuing the current script on android?
Or, does anybody know if i can add the "nohup" applet to my android device?
Thanks again to all who reply!

You can use daemonize to run your script:
Usage: daemonize [-f logfile] [-a] [-d delay] <program>

Related

starting monkeyrunner but only jyphon starts

please can someone help i have not done this for a while. I am trying to execute a monkeyrunner python script. In my c:\Android\sdk\tools\bin directory i run the following: monkeyrunner monkeyRun.py. Nothing happen only jython command line starts
Passing the script file to the monkeyrunner is the right thing to do, see https://developer.android.com/studio/test/monkeyrunner/index.html.
If you provide a filename as an argument, the monkeyrunner command runs the file's contents as a Python program; otherwise, it starts an interactive session.

QPython Android Kivy, launch python script from a python script

I'm getting a permission denied error when my QPython android script tries to launch another qpython script.
I'm assuming that this can be done - right?
I've tried subprocess.call, whic seems like the right thing to do.
But, the script doesn't run, and the log shows the permission denied error.
The obvious thing to do is look at the permissions of the sub script, but I don't know how to do that on my Android phone.
Any comments/suggestion appreciated.
Thanks.
First, how to open a command prompt(bash)
Actually qpython = terminal emulator + Python code editor + Python interpreter.
So of course you can use the console! Why you can't enter bash is because every time you click the console icon in qpython it runs python. Just type something which will cause the interpreter error like "I want bash!" then run it, interpreter will break then go back to bash.
Second, how qpython run your script
It pass your python script to a shell script(qpython.sh), then run the your script by a python interpreter.
Third, about the permissions
Why permission denied? You can't run a python script directly because it's not marked as executable. But you can pass the script's path to python interpreter to run it.
Finally, so how to call a python script by a python script in qpython?
#-*-coding:utf8;-*-
#qpy:2
#qpy:console
import subprocess
print("I am calling myself!")
pysh="/data/data/org.qpython.qpy/files/bin/qpython-android5.sh"
#if U R using android 5
#else
pysh="/data/data/org.qpython.qpy/files/bin/qpython.sh"
callpy=__file__
#the script path you want to run
subprocess.call([pysh,callpy])
Hope this help you!
(I can't add image by myself because I don't have that much reputation, I need someone else to change my image link to image. So if you like my answer, please vote me. Thanks.)
Once you know where the script is, just move to that folder and then use the following command to list the files:
ls -l
the command outputs all the files together with permission (first column).
Now, to change the permission to "execution" you can use:
chmod 755 [your-script-name]

SL4A don't work in terminal ide of my android

I have HTC One X, with Android 4. I have install sl4a, python, scapy and terminal IDE on my smartphone. All is alright, python in terminal IDE work well with scapy as root.
The problem happens when i use SL4A.
droid=android.Android(('127.0.0.1', '58322'))
droid.makeToast('Hello, Android!')
When i run the script there is no error, but at interpretation of makeToast() the program stops and nothing happens.
Anyone can help me to run a python script as root with SL4A in Terminal ?
I can tell you how to run it as root, but first let me mention that I do not believe that this is your issue. To make sure, try running this script:
# author: Matthew Downey
# purpose: Hello World.py script for android with SL4A
import android #this makes sure you can run android functions
droid = android.Android()
droid.makeToast('Hello, Android!') #uses the android module to display a user message
This should run fine, and does not require root. However if you are running a python script on your android that does require root (say you are using subprocess.call(command) to execute a command that requires root), try this (from the terminal on your android):
app_148#cdma_spyder:/ $ cd filepath_to_mypythonprogram/myProgram.py
app_148#cdma_spyder:/ $ su
app_148#cdma_spyder:/ # python myProgram.py
This should effectively run the python script as root, assuming your phone is rooted!
This might be of help: https://groups.google.com/forum/?fromgroups=#!searchin/python-for-android/socket.gaierror/python-for-android/s1rX9fTYPQQ/6_pHEm13gQwJ
Also your port shouldn't be in single quotes.

how to run script at boot-time?

I need to run a script that sets cpu_freq .In order to retain the settings after reboot i need to run script which takes care of this issue.I tried to write service in init.rc but the edited part in init.rc disappears on reboot .is there some other way to start script on reboot.thanks
I've found success with magisk. When installed, it adds a directory for boot scripts under /data/adb/service.d, in which you can throw your shell scripts and have them executed by Magisk on boot.
For example, I have the following script:
#!/bin/sh
sleep 15 # to make sure we aren't running in an early stage of the boot process
crond -b -c /data/crontab/
Once created as /data/adb/service.d/start-crond.sh and made executable, it automatically launches crond at boot (provided by Magisk's internal busybox instance).
Use Script Manager.
This link may be helpful:
[ADDON][Xperia S] Generic startup/init.d scripts support for Stock ROM/Kernel
http://forum.xda-developers.com/showthread.php?t=1547238
Although it is for Xperia S, it also works for my ideos. I think the theory behind is quite generic. And if you have installed busybox, you can unzip the downloaded package, read the batch and make some change to the phone by yourself.
If you really want to run your script manually after boot, I prefer scriptme in play market. It's simple and small.

Launching an Android Emulator from Python-Django

def start_test(request):
os.system('echo Starting emulator...')
os.system('./android-sdk-linux_x86/tools/emulator -avd testavd &')
return HttpResponse("OK")
Here is the barebones code of what I am trying to do.
When this code gets executed, the server stops responding while running the emulator. Any help appreciated.
I am using the django development server. Here is the server output:
Django version 1.1.1, using settings 'Cloust.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Starting emulator...
[21/Apr/2011 02:00:06] "GET /start_test/a.apk/ HTTP/1.1" 200 5
emulator: warning: opening audio output failed
emulator: emulator window was out of view and was recentred
Maybe you should try to run emulator in separate thread?
E.g.
import subprocess
thread = threading.Thread(target=subprocess.popen(['./android-sdk-linux_x86/tools/emulator', '-avd', 'testavd', '&'])
thread.start()
Considering you are using django you will probably need to manage the emulators somehow.
Threading is not really a good option in this case I think.
I'd suggest looking into task management in this case with something like http://code.google.com/p/django-tasks/
Don't know if it will help so one (hope it does).
I wanted the emulator to open before automation testing starts and for some reson appium can't do it.
in my case I needed to add the full path of the emulator.
check_output(["/Users/{USER_NAME}/Library/Android/sdk/tools/emulator", "-avd", "Pixel_API_26"])
Hope it will help someone until appium will fix this problem.
I still haven't gotten around to properly solving this problem, but using subprocess.Popen allows me to perform commands on the emulator afterwards:
print 'Starting emulator...'
subprocess.Popen(['emulator', '-avd', 'testavd'])
os.system('adb wait-for-device')
os.system('Perform whatever adb commands you need')
It's worth noting that this is using the django development server, which has been started using sudo, so obviously this is far from ideal.
One problem with ADB is that you need multiple commands to get things done.
For example:
adb shell
su
cp /data/local/x /data/local/y
exit
adb pull /data/local/y
Can this be done using python popen and os-system? Tried the example below without success..
print 'Starting emulator...'
subprocess.Popen(['emulator', '-avd', 'testavd'])
os.system('adb wait-for-device')
os.system('Perform whatever adb commands you need')

Categories

Resources