<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7036.0">
<TITLE>How to invoke an external C program and output an integer to the program?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Hi,</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">I want to call an extension like 88888 and invoke an external C program upon calling, pass an constant integer like 1 to the C program.</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">What I have done is:</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B><FONT SIZE=2 FACE="宋体">/etc/extensions.conf</FONT><FONT SIZE=2 FACE="宋体">:</FONT></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">exten => 88888,1,system(/usr/local/src/parallel/fire 1)</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">exten => 88888,</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">n</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">,</FONT></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="宋体">Dial(</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">SIP/</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">88888)</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">exten => 88888,</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">n,Hangup</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">t</FONT><FONT SIZE=2 FACE="宋体">he C program under</FONT><FONT SIZE=2 FACE="宋体"></FONT> <FONT SIZE=2 FACE="宋体">/usr/local/src/parallel/fi</FONT><FONT SIZE=2 FACE="宋体">r</FONT><FONT SIZE=2 FACE="宋体">e</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体"> will wait for the input, if it's 1 external LED light will be on</FONT><FONT SIZE=2 FACE="宋体">, if it's 0 LED light will be off.</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">I have changed the file ownership and group since my asterisk user is asterisk</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体"> (</FONT><FONT SIZE=2 FACE="宋体">with freepbx</FONT><FONT SIZE=2 FACE="宋体">)</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">:</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B><FONT SIZE=2 FACE="宋体">[root@Fire-Station parallel]# ls -l fire*</FONT></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">-rwxrwxrwx 1 asterisk asterisk 5882 Oct 16 09:18 fire</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">-rw-r</FONT><FONT SIZE=2 FACE="宋体">w-rw- 1 asterisk asterisk 2793 Oct 15 22:25 fire.c</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B><FONT SIZE=2 FACE="宋体">If I run the program separately everything is fine:</FONT></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">[root@Fire-Station parallel]# /usr/local/src/parallel/fire 1</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">buffer is 1</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">input1 value is 1</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">open port successfully</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Input1 is high, Pin 17 set to high</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Input1 is 1</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">[root@Fire-Station parallel]# /usr/local/src/parallel/fire 0</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">buffer is 0</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">input1 value is 0</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">open port successfully</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Input1 is low, Pin 17 set to low</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Input1 is 0</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">[root@Fire-Station parallel</FONT><FONT SIZE=2 FACE="宋体">]#</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">However if I call to 88888 I can see it execute the system command but it doesn't output an integer</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体"> 1 to my</FONT> <FONT SIZE=2 FACE="宋体">'</FONT><FONT SIZE=2 FACE="宋体">fire</FONT><FONT SIZE=2 FACE="宋体">'</FONT><FONT SIZE=2 FACE="宋体"> program</FONT><FONT SIZE=2 FACE="宋体">.</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><B><FONT SIZE=2 FACE="宋体">CLI:</FONT></B></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">-- Executing System("SIP/10-09a63138", "/usr/local/src/parallel/fire 1") in</FONT></SPAN><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体"></FONT></SPAN><SPAN LANG="en-us"> <FONT SIZE=2 FACE="宋体">new stack</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Any ideas on this or I shouldn't use System() at all?</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Thanks & Best Regards,</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2> </FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="宋体">Johnny Xing</FONT></SPAN><SPAN LANG="en-us"></SPAN></P>
</BODY>
</HTML>