Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Executing a Ruby script from Asterisk

To run a Ruby script from Asterisk you need 2 things 1) an extension to run the script from 2) a Ruby script.

* Preparing the evironment *
1) create a script directory for Asterisk and ensure it has permission to run the scripts.

* Running the script *
1) Dial extension 3000
2) Listen to the voice say 'hello world'
3) Observe a new output.txt file has been created containing the message 'hello world!'

file: hello-world.rb
#!/usr/bin/ruby

#file : hello-world.rb

file = File.new('/etc/asterisk/ruby/output.txt','w')
file.puts 'hello world!'
file.close

file: extensions.rb
exten => 3000,1,Playback(hello-world)
exten => 3000,n,System(/etc/asterisk/ruby/./hello-world.rb)
exten => 3000,n,Hangup


file: output.txt
hello world!

Auto-store all request variables

// Puts all request variables into local variables. Never type request.querystring again. Easily modified to work with option explicit.

<%
	For each item in Request.querystring
		If not len(item) <= 0 Then
			Execute("[" & item & "] = Request(""" & item & """)")
		End If
	Next

	For each item in Request.form
		If not len(item) <= 0 Then
			Execute("[" & item & "] = Request(""" & item & """)")
		End If
	Next
%>

run a external command from python

with new subprocess module (py2.4)
from subprocess import Popen,PIPE

p = Popen(file, shell=True,stdout=PIPE,stderr=PIPE)
out = string.join(p.stdout.readlines() )
outerr = string.join(p.stderr.readlines() )


with old way :
import os
out= string.join(os.popen(file).readlines())


or
os.spawnvp(os.P_WAIT,"/usr/bin/mplayer",["","-ao","pcm",file])

# or 

os.spawnvp(os.P_NOWAIT,"/usr/bin/mplayer",["","-ao","pcm",file])

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS