3

I am running a simple client-server program written in python, on my android phone using QPython and QPython3. I need to pass some commandline parameters. How do I do that?

Pacu
  • 163
  • 1
  • 2
  • 8

2 Answers2

1

I found a couple of way of running a script that I imported from my Linux laptop.

If I put frets.py in the script3 directory, and create this script in the same directory:

import sys, os
dir = '/storage/emulated/0/com.hipipal.qpyplus/scripts3/'
os.chdir(dir)        
def callfrets(val):
    os.system(sys.executable+" frets.py " + val)
while True:
    val = input('$:')
    if val:
        callfrets(val)
    else:
        break

I can run the program with the same commandline inputs that I used in Linux, getting output on the console. Just invoke this script from the editor or the programs menu.

I also found (after getting some argparse errors) that I can get to a usable Linux shell by quiting the Python console with sys.exit(1):

import sys
sys.exit(1)

drops me into the shell with the / directory. Changing directory

cd /storage/emulated/0/Download  # or to the scripts3 directory

lets me run that original script directly

python frets.py -a ...

This shell has the necessary permisions and $PATH (/data/data/com.hipipal.qpy3/files/bin).

(I had problems getting this working on my phone, but updating Qpython3 took care of that.)

hpaulj
  • 221,503
  • 14
  • 230
  • 353
0

Just write a wrapper script which get the parameters and pass to the real script using some function like execfile, and put the script into /sdcard/com.hipipal.qpyplus/scripts or /sdcard/com.hipipal.qpyplus/scripts3 (for qpython3).

Then you can see the script in scripts when clicking the start button.

River
  • 66
  • 2