Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SYS module

Status
Not open for further replies.

veloman

IS-IT--Management
Jan 27, 2005
1
US
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()


 
I think the problem is at line:
sys.stdout.write('VERBOSE “Script Started” 3 ')
If you put other quotations(like normal ones):
sys.stdout.write('VERBOSE "Script Started" 3 ') it must work...it says smth about not having in the ASCII the characters you put into it.Hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top