A
Amnon82
Gast
Ich hab folgenden Code in Pascal/Delphi:
Diesen hab ich nach Pascal/Lazarus übersetzt:
Dieser startet einen Process und wartet auf seine Beendigung. Zugleich werden die Application.ProcessMessages weiter ausgegeben. Somit friert das Programmfenster nicht ein. Ist das Gleiche auch unter Java möglich?
Hier mal ein standard Code zum exteren Programmaufruf:
müsste doch gehen ...
Code:
procedure RunAndWaitShell(Executable, Parameter: STRING; ShowParameter: INTEGER);
var
Info: TShellExecuteInfo;
pInfo: PShellExecuteInfo;
exitCode: DWord;
begin
{Pointer to Info}
pInfo := @Info;
{Fill info}
with Info do
begin
cbSize := SizeOf(Info);
fMask := SEE_MASK_NOCLOSEPROCESS;
wnd := application.Handle;
lpVerb := NIL;
lpFile := PChar(Executable);
{Parametros al ejecutable}
{Executable parameters}
lpParameters := PChar(Parameter + #0);
lpDirectory := NIL;
nShow := ShowParameter;
hInstApp := 0;
end;
{Execute}
ShellExecuteEx(pInfo);
{Wait to finish}
repeat
exitCode := WaitForSingleObject(Info.hProcess, 500);
Application.ProcessMessages;
until (exitCode <> WAIT_TIMEOUT);
end;
Diesen hab ich nach Pascal/Lazarus übersetzt:
Code:
//Processandwait example by Amnon82
//Version 20070312-1
//
//Create a form with one button on it.
//Copy this sourcecode to your pas.
//Compile it in lazarus.
unit unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons, Process;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure Processandwait(Executable : String);
var
AProcess1: TProcess;
exitcode, i : integer;
begin
I:= 0;
try
AProcess1 := TProcess.Create(nil);
AProcess1.CommandLine := Executable;
AProcess1.Options := AProcess1.Options;
{Execute}
AProcess1.Execute;
{Wait to finish}
while AProcess1.running = true do
begin
I:= I + 1;
sleep (300);
form1.caption := ' L:'+ inttostr(i);
Application.ProcessMessages;
end;
finally
AProcess1.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Processandwait('gedit');
Showmessage('gedit closed');
end;
initialization
{$I unit1.lrs}
end.
Dieser startet einen Process und wartet auf seine Beendigung. Zugleich werden die Application.ProcessMessages weiter ausgegeben. Somit friert das Programmfenster nicht ein. Ist das Gleiche auch unter Java möglich?
Hier mal ein standard Code zum exteren Programmaufruf:
Code:
class ExecProcess {
public static void main(String[] argumentes) {
try {
Runtime.getRuntime().exec("gedit");
}
catch (Exception ex) {
System.out.println(ex);
}
}
}
müsste doch gehen ...