Please help me with some questions about running AGI scripts, thank you very much!

Executing [6005@from-internal:1] Answer(“PJSIP/6001-0000000c”, “”) in new stack
[2024-11-08 15:32:49] VERBOSE[17118][C-0000000d] pbx.c: Executing [6005@from-internal:2] EAGI(“PJSIP/6001-0000000c”, “/var/lib/asterisk/agi-bin/stream_to_java.py”) in new stack
[2024-11-08 15:32:49] VERBOSE[17118][C-0000000d] res_agi.c: Launched AGI Script /var/lib/asterisk/agi-bin/stream_to_java.py
[2024-11-08 15:32:49] VERBOSE[17118][C-0000000d] res_agi.c: <PJSIP/6001-0000000c>AGI Script /var/lib/asterisk/agi-bin/stream_to_java.py completed, returning 0
[2024-11-08 15:32:49] VERBOSE[17118][C-0000000d] pbx.c: Executing [6005@from-internal:3] Hangup(“PJSIP/6001-0000000c”, “”) in new stack

The log shows that the execution was successful, but the log file that was supposed to be generated in my stream_to-jav.py script was not successfully generated. What is the reason for this

Because there is something wrong in the script. However you did not provide us with the contents of the script. At least one fault is likely to be failing to check that writing the log worked, or failing to set an error return code, if it didn’t/

Asterisk sets stderr to /dev/null when it spawns your script. This can make it quite difficult to debug, because any error messages will completely disappear.

To get around this, put something like the following close to the top of your script:

import os
log = open("/tmp/agi_try.log", "w")
os.dup2(log.fileno(), 2)
log.close()
del log

Check file write permissions.

asterisk> agi set debug on

May yield clues.

sure,there are my script contents.

#!/usr/bin/env python
import sys
sys.stderr.write(“EAGI script started\n”)

with open(“/tmp/stream_to_java.log”, “a”) as log_file:
log_file.write(“EAGI script started successfully.\n”)

sys.stderr.write(“Testing EAGI script functionality…\n”)
sys.stderr.write(“EAGI script completed.\n”)

yeah,i do,but no file in tmp.

Does your script run from the command line?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.