Running external program like Units or Xmms-shell lazarus / 13-General ---------------------------------------------------------------------- MyIden · 2006-07-06 12:44 Can anyone help me .. i want to write a program like frontend for console program for example Units or Xmms-Shell -r .. the problem is that these programs are not terminating.. the main idea is to push data to the console program while it's running and get response. Another question is how to operate with Xmms with my program without using Xmms-shell ( play, pause, stop, loading files, volume etc like with Xmms-shell ?? ) ---------------------------------------------------------------------- Marc · 2006-07-07 08:16 See wiki: http://wiki.lazarus.freepascal.org/index.php/Executing_External_Progra ms ---------------------------------------------------------------------- MyIden · 2006-07-07 09:23 I know that page. :? The problem is that i don't know how to operate with programs like for example 'xmms-shell -r'. 1. I just run 'xmms-shell -r' interactive mode 2. Then i have to pass some parameters to the program 'play' or 'list' 3 . the recive responce, if any. When i don't need it anymore then i'm terminating Xmms-shell with command 'quit'. Examples on Wiki page are showing how to open program with inline parameters and to get response when program finishes. i've tried to use streams from last example to get response and to transfer data to the program but i don't know how. I've tried to use Process.output.readstring and process.input.readstring. What i get is just hanging application, I'm just beginer. Mabe someone could give me somme address with more informations ( i did google but i did't found much ) or some examples .. :?: ---------------------------------------------------------------------- Anonymous · 2006-07-07 12:21 Maybe having a look at cmdlinedebugger.pp (typically in /usr/lib/lazarus/debugger/) could help. Lazarus is "talking" to gdb this way. ---------------------------------------------------------------------- Marc · 2006-07-08 00:38 Look at the 3rd example. While in the loop op retrieving output, you can also send commands using the input pipe. You don't have to quit the loop if there is no more info to read. You can define your own loop. ---------------------------------------------------------------------- MyIden · 2006-07-08 15:55 Ok but before i will pass some data to an external program  program it would be nice to get some welcome message example : ************************* maciek@Nexus:~$ xmms-shell -r Waiting for XMMS to start... Message: device: default .done! [11/11] Indios Bravos - mental revolution (state of sound version) (stopped)>  ************************* xmms-shell is waiting for data example 'play' / But .. The probem is that my test program does not get these data ( The test program from Wiki works fine 'ppc386 -h' - of cource output is limited , but it's just for test. ) When command line is 'xmms- shell -r' program runs Xmms and stops using 99% of processor. Any Ideas ??   procedure TForm1.Button1Click(Sender: TObject); var S:String; Result:longint; begin   Memo1.Text := ''; S := '' ;   SetLength(S,2048);   Process1.CommandLine := 'xmms-shell -r'; // 'ppc386 -h' works fine   Process1.Options := [poUsePipes];   Process1.Execute ;   While Process1.Running do   begin        Result := Process1.OutPut.Read(S[1],2048);        if Result > 0 then begin        Memo1.Text := Memo1.Text + S ;        S:='';        sleep(100) ;        end;   end;   Result := Process1.OutPut.Read(S[1],2048);   if Result > 0 then begin   Memo1.Text := Memo1.Text + S ;   S:='';   Process1.Free;   end; end; ---------------------------------------------------------------------- Marc · 2006-07-10 09:32 ??? the xmms-shell sources I found don't have a -r switch. What returns xmms-shel -h ? BTW, maybe add an application.processmessages after the line you add text to a memo. BTW2, why using xmms-shell and not using the xmms-remote commands directly ? ---------------------------------------------------------------------- Anonymous · 2006-07-10 11:08 Hmm .. xmms-shell -h does not work either. ?? Why ??  when i put as shellcommand ' mount ' it works and i get list of mounted partitions + some processmessages , I use Ubuntu 6.6 and xmms-shell form repositores xmms-shell -r starts interactive console session. BTW .. OK I would like to use xmms_remote but i don't know how ... I translate xmmsctrl.h but i'm not shure if i dit it correctly .. ( it compiles but when i write a litlle program like : begin   if xmms_remote_is_running(0) then begin       xmms_remote_play(0);       writeln('done');       end; end; nothing is happening.. ) The 'unit xmmsctrl' i translated using h2pas and i had to changed some variable types as gint to integer , gfloat to longint , gchar to char , gboolean to boolean, and pglist to Tstringlist... it does not even go into the if section ( xmms_remote_is_running returns false, but xmms is running ) following code was written by someone else and it works #include #include main() {     if(xmms_remote_is_running(0))     {         xmms_remote_play(0);         printf("ok\n");     } } ---------------------------------------------------------------------- Marc · 2006-07-10 12:39 Quote from: "Anonymous"Hmm .. xmms-shell -h does not work either. ?? Why ??  when i put as shellcommand ' mount ' it works and i get list of mounted partitions + some processmessages , I use Ubuntu 6.6 and xmms-shell form repositores xmms-shell -r starts interactive console session. I think the problem is in the way xmms-shell is handlig the input. Looking at the mainsource, I'm a bit worried Code: [Select]     if(isatty(fileno(in))) {         context = new InteractiveContext();     } else {         context = new FileContext(in);     } Inside tprocess, we're not a tty, so I think this wrapper treats the input as a file. But maybe you have newer sources (this is 0.99.3) Quote BTW .. OK I would like to use xmms_remote but i don't know how ... I translate xmmsctrl.h but i'm not shure if i dit it correctly .. ( it compiles but when i write a litlle program like : begin   if xmms_remote_is_running(0) then begin       xmms_remote_play(0);       writeln('done');       end; end; nothing is happening.. ) The 'unit xmmsctrl' i translated using h2pas and i had to changed some variable types as gint to integer , gfloat to longint , gchar to char , gboolean to boolean, and pglist to Tstringlist... When translating headers, the types used have to be exact the same. You cannot make things up. a pglist is defenately not the same as a TStringlist and a gfloat is not an integer. With those g prefixes it looks like they are defined in the glib unit. (look in the top of the headerfile if they include glib) Quote it does not even go into the if section ( xmms_remote_is_running returns false, but xmms is running ) following code was written by someone else and it works #include #include main() {     if(xmms_remote_is_running(0))     {         xmms_remote_play(0);         printf("ok\n");     } } Have you a url to the xmmsctrl.h and how did you translate xmms_remote_is_running and xmms_remote_play Marc