python with echo
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Wed Nov 11 22:07:12 EST 2009
On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote:
> List,
>
> I have a question of python using echo.
>
> POWER = 14
> return_value = os.system('echo 14 >
> /sys/class/net/wlan1/device/tx_power')
>
> can assign 14 to tx_power
>
> But
> return_value = os.system('echo $POWER >
> /sys/class/net/wlan1/device/tx_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
0
> 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.
Have you tried this in the shell, without involving Python? I will almost
guarantee that Python is irrelevant to the problem.
--
Steven
More information about the Python-list
mailing list