how to convert terminal command to my program?

*nix specific usage questions
SiddeeqHssn
Blank Cone
Blank Cone
Posts: 14
Joined: 03 Feb 2010 18:23

how to convert terminal command to my program?

Postby SiddeeqHssn » 18 Apr 2010 17:20

hi all
i use ubuntu 9.04 and i can use vlc commands from terminal like

Code: Select all

vlc -vvv /home/siddeeq/11.mp3 --sout udp:239.255.42.42 --ttl 12
for stream mp3 file but i need to use this command i my program written in c. what function in need? and how i can use them? i try this code but it's not work

Code: Select all

#include <stdio.h> #include <stdlib.h> #include <vlc/vlc.h> static void raise(libvlc_exception_t * ex) { if (libvlc_exception_raised (ex)) { fprintf (stderr, "error: %s\n", libvlc_exception_get_message(ex)); exit (-1); } } int main(int argc, char* argv[]) { const char commands[] ={" vlc -vvv /home/siddeeq/11.mp3 --sout udp:239.255.42.42 --ttl 12"}; const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--plugin-path=/set/your/path/to/libvlc/module/if/you/are/on/windows/or/macosx" }; libvlc_exception_t ex; libvlc_instance_t * inst; libvlc_media_player_t *mp; libvlc_media_t *m; libvlc_exception_init (&ex); /* init vlc modules, should be done only once */ inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &ex); raise (&ex); /* Create a new item */ m = libvlc_media_new (inst,commands, &ex); //// m = libvlc_media_new (inst, "/home/siddeeq/1.wmv", &ex); //work ok raise (&ex); /* XXX: demo art and meta information fetching */ /* Create a media player playing environement */ mp = libvlc_media_player_new_from_media (m, &ex); raise (&ex); /* No need to keep the media now */ libvlc_media_release (m); /* play the media_player */ libvlc_media_player_play (mp, &ex); raise (&ex); sleep (10); /* Let it play a bit */ /* Stop playing */ libvlc_media_player_stop (mp, &ex); /* Free the media_player */ libvlc_media_player_release (mp); libvlc_release (inst); raise (&ex); return 0; }
thank you

babitha
Blank Cone
Blank Cone
Posts: 25
Joined: 15 Jan 2008 08:01

Re: how to convert terminal command to my program?

Postby babitha » 03 Jun 2010 14:13

Hi Sideeq,
You can use execvp() to call the terminal commands.
eg:
string param1;
param1="-vvv";
param2 = "/home/siddeeq/11.mp3";
param3 = ":sout=#duplicate{dst=std{access=udp,dst=239.255.42.42}}";
param4 =":ttl=12";
char* arg_list[] = {"vlc",(char*)param1.c_str(),(char*)param2.c_str(),(char*)param3.c_str(),(char*)param4.c_str(),NULL};
execvp("vlc,arg_list);

Note:Before using execvp u need to fork() the process.Try it.

Regards,
Babitha


Return to “VLC media player for Linux and friends Troubleshooting”

Who is online

Users browsing this forum: No registered users and 4 guests