classification
Title: commands has no "RANDOM" environment?
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: addict2tux, vstinner, zach.ware
Priority: normal Keywords:

Created on 2014-02-20 22:55 by addict2tux, last changed 2014-06-20 15:53 by zach.ware. This issue is now closed.

Files
File name Uploaded Description Edit
commands_bug.py addict2tux, 2014-02-20 22:55 commands_bug.py
Messages (3)
msg211759 - (view) Author: Yanming Xiao (addict2tux) Date: 2014-02-20 22:55
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)
msg211761 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-20 22:58
I'm not sure that commands.getstatusoutput() will use the same shell than your shell. Try to display $SHELL environment variable to know your shell.
msg221099 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-06-20 15:53
Since commands is deprecated, closing the issue.
History
Date User Action Args
2014-06-20 15:53:18zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg221099

resolution: wont fix
stage: resolved
2014-02-20 22:58:01vstinnersetnosy: + vstinner
messages: + msg211761
2014-02-20 22:55:09addict2tuxcreate