Issue32760
Created on 2018-02-03 21:24 by JamesDinhBugPython, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg311572 - (view) | Author: JamesDinh (JamesDinhBugPython) | Date: 2018-02-03 21:24 | |
Hi Python dev. team,
I would like to report below error:
1) Tittle: Running Linux shell command from python file always leads to reset config error.
2) Environment:
+ Linux distro: Both Ubuntu 16.04 64b and Fedora 25 happen this issue
+ Python:
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
3) Reproduce route:
These commands can be run normally from Linux terminal:
[I use buildroot for my embedded project]
./configure O=output project_name debug initramfs nofirewall
make O=output
But when I tried to call them from Python file, the configure command always lead to Restart config... - and all the new configuration values are discarded.
For your information, I tried these options:
a)
spkConfigureCmd = ["./configure","O=output", "project_name","debug","initramfs","nofirewall"]
subprocess.check_call(spkConfigureCmd)
spkBuildCmd = ["make","O=output"]
subprocess.check_call(spkBuildCmd)
b) os.system("./configure O=output project_name debug initramfs nofirewall && make O=output")
c)
fid = open('ax2spkbuild.sh','w')
fid.write('./configure O=output project_name debug initramfs nofirewall\n')
fid.write('make O=output\n')
fid.close()
os.system('chmod +x ax2spkbuild.sh')
os.system('./ax2spkbuild.sh')
Actually I tried with another simple command like 'pwd', 'cat', 'echo' and they are working well. I wonder how come Python executes the Linux shell commands, which are slightly different to the Terminal typed commands.
|
|||
| msg311650 - (view) | Author: JamesDinh (JamesDinhBugPython) | Date: 2018-02-05 08:19 | |
Hi, From this stackoverflow thread: https://stackoverflow.com/questions/716011/why-cant-environmental-variables-set-in-python-persist I find out there is an abnormal environment variable setting affects by using shell command. Do you have some explanation for the shell command runs? For your information, if I run below commands: os.system("export MYENVPATH=/opt/toolchain/gcc") os.system("./configure O=output project_name debug initramfs nofirewall && make O=output") Then the configure command can't detect the MYENVPATH value. |
|||
| msg311672 - (view) | Author: Stéphane Wirtel (matrixise) * ![]() |
Date: 2018-02-05 16:00 | |
It's normal, when you execute a command, there is a fork/exec, fork for the new process, and the exec will replace the memory of the previous process by the new process.
in os.system, you use ('export MYENVPATH=/usr/bin/gcc') but this variable only exists for the $SHELL process, once this one is finished, the variable is just destroyed.
You have to pass all the env variables when you call your process, read the doc of subprocess.Popen, there is a env variable, you have to pass the value to this parameter
https://docs.python.org/2.7/library/subprocess.html?highlight=subprocess#subprocess.Popen
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:57 | admin | set | github: 76941 |
| 2018-02-05 16:00:36 | matrixise | set | status: open -> closed nosy:
+ matrixise stage: resolved |
| 2018-02-05 08:19:42 | JamesDinhBugPython | set | messages: + msg311650 |
| 2018-02-03 21:24:00 | JamesDinhBugPython | create | |
