Script returns output in IDLE not when executed at CLI
Question: I have a script that runs a few external commands and returns their values. I
am able to run the script within IDLE just fine, and I get the expected
results.

When I execute the script in a Linux shell (Bash), it runs, but with no
output.

The exit status is 0.

    
    
    #!/usr/bin/python
    
    import array,os,subprocess
    
    
    def vsdIndex(vmVsd):
       index = subprocess.call(["/root/indeces.sh", vmVsd], stdout=subprocess.PIPE, shell=TRUE).communicate()[0]
       print index
    return (firstSerial,lastSerial)
    
    def main():
    
        vsdArray = []
        vsdProc = subprocess.Popen(["sc vsd show | tail -n +2 | grep -Ev 'iso|ISO|vfd' | awk '{{print $1}}'"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
        while True:
           line = vsdProc.stdout.readline()
           if line != '':
              vsdIndex(line) 
              print "VSD:", line.rstrip()
              print firstSerial
              print lastSerial
           else:
              break
    

If I simplify it, and run without the function, I have the same behaviour:

    
    
    def main():
    
        vsdArray = []
        vsdProc = subprocess.Popen(["sc vsd show | tail -n +2 | grep -Ev 'iso|ISO|vfd' | awk '{{print $1}}'"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
        while True:
           line = vsdProc.stdout.readline()
           if line != '':
              print "VSD:", line.rstrip()
           else:
              break
    


Answer: You need to call your main() function. Here is a common way of doing that
automatically when you run on the command line:

    
    
    if __name__ == "__main__":
        main()
    

