From: Michael B. <mbe...@gm...> - 2014-04-20 07:07:41
|
ok, I redirected stderr to a file, here it is: begin log____________________________________________________________________ Traceback (most recent call last): File "/var/lib/asterisk/agi-bin/voicecmd_py.agi", line 76, in <module> check_call([cmd,arg1,arg2], shell=False) File "/usr/lib64/python2.6/subprocess.py", line 500, in check_call retcode = call(*popenargs, **kwargs) File "/usr/lib64/python2.6/subprocess.py", line 478, in call p = Popen(*popenargs, **kwargs) File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__ errread, errwrite) File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory ___________________________________________________________________________ end log and here is the agi itself: begin script__________________________________________________________________ #!/usr/bin/env python from subprocess import * from asterisk.agi import * import os import sys sys.stdout = open('/tmp/pyoutfile', 'w') sys.stderr = open('/tmp/pyerrfile', 'w') #print "hello" #def main(): agi = AGI() agi.verbose("python agi started", 1) callerId = agi.env['agi_callerid'] agi.verbose("call from %s" % callerId) cmd = agi.env['agi_arg_1'] agi.verbose("command text: %s" % cmd) cmd = cmd.lower() words = cmd.split() for word in words: agi.verbose("word: %s" % word) if any("theater" in s for s in words): room = "theater" elif any("kitchen" in s for s in words): room = "kitchen" elif any("master" in s for s in words): room = "masterbedroom" elif any("season" in s for s in words): room = "3season" elif any("outside" in s for s in words): room = "deck" else: room = "none" if any("light" in s for s in words): item = "light" elif any("music" in s for s in words): item = "music" else: item = "none" if any("off" in s for s in words): value = "off" elif any("medium" in s for s in words): value = "medium" elif any("on" in s for s in words): value = "on" else: value = "none" agi.verbose("room: %s" % room) agi.verbose("item: %s" % item) agi.verbose("value: %s" % value) if (item == "music") and (value == "on" or value == "off") and (not room == "none"): fullcmd = "squeezy" + " -" + room + " -" + value cmd = "squeezy" arg1 = "-" + room arg2 = "-" + value agi.verbose(cmd) agi.verbose(arg1) agi.verbose(arg2) agi.verbose(fullcmd) #out = os.system(fullcmd) check_call([cmd,arg1,arg2], shell=False) agi.verbose("python agi ended") ________________________________________________________________________ end script if I run this in an outside python script it works just fine, no errors, I've run it as asterisk and root begin script_________________________________________________________________ #!/usr/bin/env python from subprocess import * import os cmd = "turn outside music on" words = cmd.split() for word in words: print "word: %s" % word if any("theater" in s for s in words): room = "theater" elif any("kitchen" in s for s in words): room = "kitchen" elif any("outside" in s for s in words): room = "deck" else: room = "none" if any("light" in s for s in words): item = "light" elif any("music" in s for s in words): item = "music" else: item = "none" if any("off" in s for s in words): value = "off" elif any("medium" in s for s in words): value = "medium" elif any("on" in s for s in words): value = "on" else: value = "none" print "room: %s" % room print "item: %s" % item print "value: %s" % value if (item == "music") and (value == "on" or value == "off") and (not room == "none"): fullcmd = "squeezy" + " -" + room + " -" + value cmd = "squeezy" arg1 = "-" + room arg2 = "-" + value #os.system(fullcmd) check_call([cmd,arg1,arg2],shell=False) ___________________________________________________________________________ end script On Sun, Apr 20, 2014 at 2:39 AM, Michael Belleville <mbe...@gm...>wrote: > I've tried using both os.system as well as subprocess.call to invoke an > external command that is not working for me. It has something to do with > the command I am trying to run, which is squeezy, a command line interface > for logitech media center. > > I've been able to use os.system as well as subprocess.call successfully in > an agi using other commands, but not squeezy. > > I can get squeezy to work using both os.system as well as subprocess.call > in an external python script if I copy out the revelant chunk of code, but > it will not work in an agi. It works in an external python script if I run > it as either root or asterisk, so I don't think it is a permissions issue... > > If I try to run squeezy in the agi using subprocess.call or > subprocess.check_call, the python agi dies right there > > if I use os.system, the command still doesn't run as expected, but the agi > continues normally. > > I don't know how to capture any useful output since the agi dies if I try > to use subprocess.check_call. > > I don't see any of the regular python error messages in my asterisk CLI > output, the only output I see I generate myself with agi.verbose > > How can I get to what is happening in the agi? Can the python > errors/output be redirected somewhere I can see them? I have been > debugging my issues using external python scripts to test, but in this case > my issue goes away in the external script... > > I would appreciate any advice :) > > thank you very much to all for the wonderful piece of software, it is so > nice to be able to use python for agi scripts! > |