Nick
Nick

Reputation: 311

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.

Upvotes: 0

Views: 1121

Answers (2)

Kirk
Kirk

Reputation: 480

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.

enter image description here

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])

enter image description here

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.)

Upvotes: 1

Lino
Lino

Reputation: 6160

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]

Upvotes: 0

Related Questions