fixes for the linux version

This commit is contained in:
Basile Burg 2015-02-07 10:26:49 +01:00
parent 0d7d51a0d8
commit a9f68c1e66
2 changed files with 26 additions and 24 deletions

View File

@ -224,7 +224,7 @@ type
(** (**
* Returns TRUE if EXEName is running under Windows or Linux * Returns true if Exename is running under Windows or Linux
*) *)
function AppIsRunning(const ExeName: string):Boolean; function AppIsRunning(const ExeName: string):Boolean;
@ -865,7 +865,7 @@ begin
end; end;
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
function WindowsAppIsRunning(const ExeName: string): integer; function internalAppIsRunning(const ExeName: string): integer;
var var
ContinueLoop: BOOL; ContinueLoop: BOOL;
FSnapshotHandle: THandle; FSnapshotHandle: THandle;
@ -889,38 +889,37 @@ begin
CloseHandle(FSnapshotHandle); CloseHandle(FSnapshotHandle);
end; end;
{$ENDIF} {$ENDIF}
{$IFDEF LINUX} {$IFDEF LINUX}
function LinuxAppIsRunning(const ExeName: string): integer; function internalAppIsRunning(const ExeName: string): integer;
var var
t: TProcess; proc: TProcess;
s: TStringList; lst: TStringList;
begin begin
Result := 0; Result := 0;
t := tprocess.Create(nil); proc := tprocess.Create(nil);
t.CommandLine := 'ps -C ' + ExeName; proc.Executable := 'ps';
t.Options := [poUsePipes, poWaitonexit]; proc.Parameters.Add('-C');
proc.Parameters.Add(ExeName);
proc.Options := [poUsePipes, poWaitonexit];
try try
t.Execute; proc.Execute;
s := TStringList.Create; lst := TStringList.Create;
try try
s.LoadFromStream(t.Output); lst.LoadFromStream(proc.Output);
Result := Pos(ExeName, s.Text); Result := Pos(ExeName, lst.Text);
finally finally
s.Free; lst.Free;
end; end;
finally finally
t.Free; proc.Free;
end; end;
end; end;
{$ENDIF} {$ENDIF}
function AppIsRunning(const ExeName: string):Boolean; function AppIsRunning(const ExeName: string):Boolean;
begin begin
{$IFDEF WINDOWS} Result:= internalAppIsRunning(ExeName) > 0;
Result:=(WindowsAppIsRunning(ExeName) > 0);
{$ENDIF}
{$IFDEF LINUX}
Result:=(LinuxAppIsRunning(ExeName) > 0);
{$ENDIF}
end; end;

View File

@ -5,7 +5,10 @@ unit ce_dcd;
interface interface
uses uses
Classes, SysUtils, process, forms, strutils, windows, Classes, SysUtils, process, forms, strutils,
{$IFDEF WINDOWS}
windows,
{$ENDIF}
ce_common, ce_writableComponent, ce_interfaces, ce_observer, ce_synmemo, ce_project; ce_common, ce_writableComponent, ce_interfaces, ce_observer, ce_synmemo, ce_project;
type type