System call from Asterisk CLI

Hi all,

I’m trying to write a C code that make a system call. I try with trivial example system("echo mouse > file.txt"). It work well but i can’t see the result from CLI. Is there the possibility to redirect the output of system to CLI?or to open a command line windows from CLI?

Thank

PS I’m on Ubuntu 9.10 and asterisk 1.6.2 rc8

I haven’t tried this, but you could try something like system("DISPLAY=:0 xterm -e ’ ")
where DISPLAY is set to something appropriate to select your X server. I’d expect this to block until you closed the X terminal.

Hi As it just for testing just tail the log file would be the simplest.

Ian

He’ll need to use >> rather than > if he is going to tail the file.

As the question seems to imply a Unix newbie, I think one should also add that by tail the file, Ian probably means using the command:

tail -f file.txt

[quote=“david55”]He’ll need to use >> rather than > if he is going to tail the file.

As the question seems to imply a Unix newbie, I think one should also add that by tail the file, Ian probably means using the command:

tail -f file.txt[/quote]

Hi,

Yes i’m a quite Unix newbie…I don’t understand the answer, Can you explain it ?

Thank

Hi,

I have solved with the following lines

freopen("stdout.log", "w", stdout); freopen("stderror.log", "w", stderr);

They redirect stdout and stderror to file…

Changing the source is overkill. Also you need the “a” flag if you are going to run the command multiple times, but collect all the output in one log.

Normally one would capture standard error separately by using “2>stderror.log” (or “2>>stderror.log”) on the command line. I believe that syntax also works on Windows. Most people would just redirect both to the same file by going “> log.log 2>&1”, in Unix.

With my code they are already separated files.

Where can i add it inside the program? in a system()?

thank

You can put them in system. As this is an Asterisk forum, I had assumed that the system call was part of the dialplan. How are you invoking the program from Asterisk?

Even then, changing standard out and standard error within a program is not normally good practice, as it removes flexibility from the person running the program.

[quote=“david55”]You can put them in system. As this is an Asterisk forum, I had assumed that the system call was part of the dialplan. How are you invoking the program from Asterisk?
[/quote]
In the system() with the program that i would like to call, I think. I’m trying to add a feature to plug-in app_conference 2.0.1.
Now I would like to call vlc that act as streaming server.

[quote=“david55”]
Even then, changing standard out and standard error within a program is not normally good practice, as it removes flexibility from the person running the program.[/quote]

I don’t see any message from the CLI of Asterisk and so i can’t understand if the software work well. After redirection i understand the problems.