0

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

fteinz
  • 1,085
  • 5
  • 15
  • 30

2 Answers2

0

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.

user1934428
  • 19,864
  • 7
  • 42
  • 87
0

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?

Andrzej Krynski
  • 71
  • 3
  • 13
  • I have to get root permissions to run scripts. > su > python /storage/emulator/0/Download/.last_tmp.py -s && exit – fteinz Mar 24 '16 at 17:08
  • Neider sudo nor su exists in /system/bin – Andrzej Krynski Mar 24 '16 at 19:43
  • You have to root your phone and flash super user in recovery mode. If you don't know how to do it -> [link](http://www.xda-developers.com/root/) – fteinz Mar 31 '16 at 07:53
  • I can't do it due to warranty :-( – Andrzej Krynski Mar 31 '16 at 08:24
  • 1
    Your right but... If your mobile don't have a flash counter like Samsung KNOX or something like that, it should be easy to flash the stock Firmware without any proofs. And there are also tools availabe to reset the flash counter for example "Triangle Away" vor flashing directly with "Mobile Odin" fron Chainfire in Play Store. – fteinz Apr 01 '16 at 08:36
  • Great tip, perhaps i decide to use it B-) – Andrzej Krynski Apr 01 '16 at 09:48