I write some code where a python3 script is loading other scripts from an usb-stick. These scripts can be shell- or python scripts.
Found that running python scripts results in a problem related to using subprocess.run with arguments in arrayor string .
The problem is, that when using arguments as array then python opens in interactive mode. Unexpected. Have no clue where the problem is. Appreciate help.
The code can be reduced to these fragments:
The code "a.py" is basic.
Code: Select all
print("hallo A")
Code: Select all
import subprocess
# Option A
# causes an python process to open with interactive mode
#
a = [ "python3", "a.py"]
# Option B
# same problem
#
a = [ "/usr/bin/python3", "a.py"]
# Option C
# works as expected when no array but string is used.
#
a = "python3 a.py"
# execute the command
subprocess.run( a , shell=True)
print("hallo B")
Code: Select all
pi@raspberrypi:~ $ python3 b.py
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit() <-- manually entered
hallo B
pi@raspberrypi:~ $
Code: Select all
pi@raspberrypi:~ $ python3 b.py
hallo A
hallo B
pi@raspberrypi:~ $