QPython Android Kivy, launch python script from a python script - android

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]

Related

Can I start an executable in an approved application?

I've noticed that it is possible on Android to change the permissions on a file with chmod, which means we can easily execute anything from an application:
var runtime = Runtime.GetRuntime();
runtime.Exec("chmod 0755 /my/file").WaitFor();
// Then ProcessBuilder to execute it.
Would Google Play Store accept an application that takes advantage of this flaw? I can't find any documentation about it, but I confirm that it works.
Actually, I want to include ffmpeg for tasks that are too slow to be executed using MediaCodec.
(I've also noticed that the Android framework sometimes directly access to a native version of ffmpeg, so maybe I could access it directly from the phone?)
I don't know for sure if it is ok for Google Play.
However i don't think it is security issue. You will exec process with the autorisation of your app.
I hope the following example will help you.
You can try the following command line with your device connect.
adb shell
To have a shell on your devices
Then you can try to look what is inside the files for an app (replace com.your.package by the name of a debbugable apk)
ls /data/data/com.your.package
This command will failde because you have not the good permission.
Now run the following command.
run-as com.your.package
You will now exec your command line with the same permission as your app.
You can now retry the previous ls command. It will work. However it will not work for another package.
So, i think the command you will exec with your code, will be exec with the privilege of your app. So i don't think you can elevate the privilege of you app on a file with this method.

Executing python script in android terminal emulator

I installed python 2.7 in my Android device and I tried executing a python script by typing the command in terminal emulator. The problem is that although I use the full path for python the following error appears:
link_image[1997]: failed to link ./python CANNOT LINK EXECUTABLE.
I tried to add environment variables in ./~bashrc but I didn't make it. Any idea ?
OK it is solved. I followed these steps (http://code.google.com/p/python-for-android/wiki/RunPythonFromShell) but first I had to put the file standalone_python.sh in /data/ because in sdcard I had no permission to execute. And finally using 'su' I made it to run my script as root.

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.

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

How does the shell script envsetup.sh execute launch?

launch 1
Segmentation fault
** Don't have a product spec for: 'full'
** Do you have the right repo manifest?
I have tried to download different sources n repo synced. I reinstalled the Linux and then carefully did the environment, all went well till I downloaded the source and then launch.
Ok left me with no other option than to look into the shell script of envsetup.sh which is throwing this error. I would like to debug from here so I run smthing like
bash --debugger build/envsetup.sh
But I don't know how to execute launch from here. As this script runs it gives the option for launch, will try setting the breakpoint at the source of the error.
We call the shell script envsetup.sh . When this script is sourced with the command
source build/envsetup.sh
I can execute all functions in this script as commands.For anyone who might wonder . Ty

Categories

Resources