starting monkeyrunner but only jyphon starts - android

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.

Related

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]

Pass parameter through shell to python

I run python in my Android Terminal and want to run a .py file with:
python /sdcard/myScript.py
The problem is that python is called in my Android enviroment indirect with a shell in my /system/bin/ path (to get it direct accessable via Terminal emulator).
My exact question, how the title tells how to pass parameter through multiple Shell scripts to Python?
My direct called file "python" in /System/bin/ contains only a redirection like:
sh data/data/com.hipipal.qpyplus/files/bin/qpython-android5.sh
and so on to call python binary.
Edit:
I simply add the $1 parameter after every shell, Python is called through like:
sh data/data/com.hipipal.qpyplus/files/bin/qpython-android5.sh $1
so is possible to call
python /sdcard/myScript.py arg1
and in myScript.py as usual fetch with sys.argv
thanks
I don't have experience in Android programming, so I can only give a general recommendation:
Of course the naive solution would be to explicitly pass the arguments from script to script, but I guess you can't or don't want to modify the scripts in between, otherwise you would not have asked.
Another approach, which I sometimes use, is to define an environment variable in the outermost scripts, stuff all my parameters into it, and parse it from Python.
Finally, you could write a "configuration file" from the outermost script, and read it from your Python program. If you create this file in Python syntax, you even spare yourself from parsing the code.
I have similar problem. Runing my script from Python console
/storage/emulator/0/Download/.last_tmp.py -s && exit
I am getting "Permission denied". No matter if i am calling last_tmp or edited script itself.
Is there perhaps any way to pass the params in editor?

Running a script from a script in 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>

Want to run script file using system call in android NDK

I want to run script file on android Shell using Native C program.
I tried using system function but it's not working.
result = system("sh ./test.sh");
LOGD("result is %d", result);
system command returns 0 means its not executed script file successfully.
test.sh contains
echo "test...."
Android NDK application could not print test.... when this system call runs.
Even any script can not be started using system call. i checked more than 10 different scripts.
test.sh have 777 permissions
Any help would be appreciated.
where is 'sh'? and what is your '.' current directory when the application runs? try:
result = system("/system/bin/sh /full/path/to/test.sh");
Here i got the answer of this Question on Different post.
Run Shell Script file On Android Embedded Device using System function in Android NDK
thanks to all for Help

Why does MonkeyRunner fail when called using TeamCity

I have a monkeyrunner script that connects to an Android device and deploys an APK on it.
serial = '12345JKL'
device = MonkeyRunner.waitForConnection(deviceId=serial)
device.installPackage(path_to_apk)
This works flawlessly when I execute the script using the Windows command shell.
"C:\dev\android\tools\monkeyrunner.bat" "C:\dev\my_script.py" -psome_parameter
The problem is that I want to have my_script.py executed by a TeamCity (Enterprise 6.0.3) build configuration on the same PC: this fails.
Please find the stack trace here: http://pastebin.com/CjWy95c3
First I thought that TC was messing with the parameters of the script. But the command from the TC build log
[00:55:12]: Starting: "C:\dev\android\tools\monkeyrunner.bat" "C:\dev\my_script.py" -psome_parameter
in directory: C:\some_dir
was the same as in the command shell and accordingly the script could connect to the device and worked fine when I copied the command into a command shell while C:\some_dir was my current directory.
I was not able to reproduce this error outside of TC.
I want to emphasize that this all happens on the same PC (Win 7 x64). The script works when executed from the command shell but fails (always when trying to connect to a device) when triggered by the TC build configuration.
I can't think of a reason why this happens and would be very happy if somebody could point me in the right direction.
Many thanks in advance
Edit: As it turns out the problem isn't limited to MonkeyRunner.waitForConnection() but also occurs when calling MonkeyRunner.sleep(5). Stacktrace
Can it be that MonkeyRunner and TeamCity don't go along well with each other?
This is probably caused by a problem with your imports. The problem with your imports is likely because of the way that TeamCity calls MonkeyRunner. I would guess that it has to do with the current directory being messed up. Try using
import os
os.chdir("path")
to change your current directory at the top of your .py script. (Before you import monkeyrunner) I would try changing it to the directory with MonkeyRunner.
After a colleague and I have investigated the problem for three days, we could not find the source of this problem. But when we used another machine as the build agent, the issue was gone. We still don't know what caused this NullPointerException.

Categories

Resources