I am trying to get a python script to capture the environment variables from an asterisk ip pbx system. The communication between the application and the script is via STDIN/STOUT/STDERR.
As soon as the script lauches the application (asterisk) should dump a list of environment variables via STDIN which I am trying to catch in a list and write to a file. Further I am trying to send a message to STDOUT. Neither seems to be working.
As I am new to Python I wanted to make sure that my script is correct. Can anyone see anything wrong with this script?
Python Script:
======================
#!/usr/bin/env python
import sys
# Read and ignore AGI environment (read until blank line)
env = []
text_file=open("output.txt","w")
temp = ""
# Creat a list to hold all of the environment variables sent by Asterisk
# Each item is sent on a line terminated with a newline
# and the end of the list is indicated by an empty line.
# The list of items received will look something like this:
# agi_request: test.py
# agi_channel: Zap/1-1
# agi_language: en
# agi_type: Zap
# agi_callerid:
# agi_dnid:
# agi_context: default
# agi_extension: 3
# agi_priority: 1
#
while(temp != "\n"):
temp = sys.stdin.readline()
env.append(temp)
# Print out environment variable received
text_file.writelines(env)
text_file.close()
# Send Asterisk a console message for debugging
sys.stdout.write('VERBOSE “Script Started” 3 ')
sys.stdout.flush()
res = sys.stdin.readline()
sys.stderr.write("Received %s\n"%res)
sys.stderr.flush()
As soon as the script lauches the application (asterisk) should dump a list of environment variables via STDIN which I am trying to catch in a list and write to a file. Further I am trying to send a message to STDOUT. Neither seems to be working.
As I am new to Python I wanted to make sure that my script is correct. Can anyone see anything wrong with this script?
Python Script:
======================
#!/usr/bin/env python
import sys
# Read and ignore AGI environment (read until blank line)
env = []
text_file=open("output.txt","w")
temp = ""
# Creat a list to hold all of the environment variables sent by Asterisk
# Each item is sent on a line terminated with a newline
# and the end of the list is indicated by an empty line.
# The list of items received will look something like this:
# agi_request: test.py
# agi_channel: Zap/1-1
# agi_language: en
# agi_type: Zap
# agi_callerid:
# agi_dnid:
# agi_context: default
# agi_extension: 3
# agi_priority: 1
#
while(temp != "\n"):
temp = sys.stdin.readline()
env.append(temp)
# Print out environment variable received
text_file.writelines(env)
text_file.close()
# Send Asterisk a console message for debugging
sys.stdout.write('VERBOSE “Script Started” 3 ')
sys.stdout.flush()
res = sys.stdin.readline()
sys.stderr.write("Received %s\n"%res)
sys.stderr.flush()