I saw this issue on Python 2.7.3 running on FreeBSD 9.1-64 and ubuntu 12.04-64. All under BASH.
It seems that the shell for the external script does not have the access to RANDOM environment variable. If I run the script directly,
the results are OK.
# python -V
Python 2.7.3
# ls *.sh
arquery.sh randomnumber.sh
# ./commands_bug.py
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION0.log
# ./randomnumber.sh
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION0.log
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION279970795912919.log
# ./randomnumber.sh
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION0.log
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION279970795912919.log
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION309000060807371.log
# ./randomnumber.sh
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION0.log
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION20000681632594.log
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION279970795912919.log
-rw-r--r-- 1 root netvcr 9 Feb 20 17:31 SESSION309000060807371.log
#
# randomnumber.sh
#set -x
#
randomnumber=$((RANDOM*10000000000+RANDOM*100000+RANDOM))
sid=SESSION${randomnumber}
echo "whatever" > ${sid}.log
ls -l SESSION*.log
#!/usr/local/bin/python
#
# bug_in_python.py
#
import os
import commands
def main():
cmdString = './randomnumber.sh'
outputString = commands.getstatusoutput(cmdString)
print outputString[1]
#
# program starts
#
if __name__ == '__main__':
main()
os._exit(0)
|