python with echo
python at mrabarnett.plus.com
Thu Nov 12 20:30:01 CET 2009
Steven D'Aprano wrote:
> On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote:
>> I have a question of python using echo.
>> POWER = 14
>> return_value = os.system('echo 14 >
>> can assign 14 to tx_power
>> return_value = os.system('echo $POWER >
> POWER = 14 doesn't create an environment variable visible to echo. It is
> a Python variable.
>>>> POWER = 14
>>>> import os
>>>> return_value = os.system('echo $POWER')
>> return_value is 256 not 0. It cannot assign 14 to tx_power.
> I don't understand that. Exit status codes on all systems I'm familiar
> with are limited to 0 through 255. What operating system are you using?
> Assuming your system allows two-byte exit statuses, you should check the
> documentation for echo and the shell to see why it is returning 256.
In some OSs the exit status consists of 2 fields, one being the child
process's exit status and the other being supplied by the OS.
The reason is simple. What if the child process terminated abnormally?
You'd like an exit status to tell you that, but you wouldn't want it to
be confused with the child process's own exit status, assuming that it
had terminated normally.
> Have you tried this in the shell, without involving Python? I will almost
> guarantee that Python is irrelevant to the problem.
More information about the Python-list