Recent

Author Topic: How to launch a daemon?  (Read 3729 times)

winnie

  • New member
  • *
  • Posts: 8
How to launch a daemon?
« on: June 03, 2005, 04:17:43 pm »
I have a quite big problem:

I want to launch a daemon from my program, but always when I launch it, my programm hangs up... :S

I have used this Class:

Code: [Select]

unit cprozess;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Process, StdCtrls, Dialogs;
 
const
  READ_BYTES = 2048;
 
 
type TProzessdata = class(TObject)
 
     private

     public
           constructor create ();
           function execute_programm(prog:String):TStringlist;
     
     end;
     

implementation

constructor TProzessdata.create();
begin;

end;

function TProzessdata.execute_programm(prog:String):TStringList;
var
  S: TStringList;
  M: TMemoryStream;
  P: TProcess;
  n: LongInt;
  BytesRead: LongInt;
begin;
      M := TMemoryStream.Create;
      BytesRead := 0;
      P := TProcess.Create(nil);
      P.CommandLine := prog;
      P.Options := [poUsePipes];
      P.Execute;
      while P.Running do
            begin
                 M.SetSize(BytesRead + READ_BYTES);
                 n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
                 if n > 0 then
                         Inc(BytesRead, n)
                 else
                     Sleep(100);
            end;
      repeat
            M.SetSize(BytesRead + READ_BYTES);
            n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
            if n > 0 then
               Inc(BytesRead, n);
      until n <= 0;
      M.SetSize(BytesRead);
      S := TStringList.Create;
      S.LoadFromStream(M);
      P.Free;
      M.Free;
      execute_programm:=S;
end;

end.


With this Class I can execute all programms, but not Daemons, why?

I call this function so:

Code: [Select]

execute_programm('/etc/init.d/portmap start');

this runs with every other programm, e.g.: konqueror, ls- xterm... and so on

can someone help me to run a daemon?
what in this class is not correct, or better what must I change in order to run a daemon?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
How to launch a daemon?
« Reply #1 on: June 03, 2005, 04:55:56 pm »
Maybe your problems have nothing to do with daemon or not, but with the fact your are trying to start a scrupt and not a executable.

winnie

  • New member
  • *
  • Posts: 8
How to launch a daemon?
« Reply #2 on: June 03, 2005, 09:54:34 pm »
no, because this works:
Code: [Select]

execute_programm('/etc/init.d/portmap stop');


i have this failure only if i want to start (or restart) a daemon with the start-stop-daemon.

:S

winnie

  • New member
  • *
  • Posts: 8
How to launch a daemon?
« Reply #3 on: June 03, 2005, 11:14:48 pm »
ok, the starting a daemon works only if I add the --background option to the start-stop-daemon.

 

TinyPortal © 2005-2018