It seems that the IProcess.CommandLine call ocasionally fails for remote processes. (As it's not a perfect world (screws break, things falls down) it does not come as a total supprise, but I would appreciate any hints as to the cause (probably myself, I know.. ))
I have isolated the problem in a small test program (1 button, and a RichEdit) and a loop where I continously do a Process('wordpad.exe') and gets the commandline, print the result and sleeps for 100 ms.
I have this program running when I start 'wordpad' as 'C:\Programmer\Windows NT\Tilbehør\wordpad.exe' and the small test-program reports this start-path correctly as the commandline.... most of the time
If I start/stop 'wordpad.exe' a few times, suddenly the test-program reports the commandline '"wordpad.exe"' and not 'C:\Programmer\Windows NT\Tilbehør\wordpad.exe' as expected ??
Any ideas..
1) Why this happens ?
2) How you get 'back-to-normal' (i.e. start retrieving the correct path-again, without restarting the entire test-program)
Code sniplet is attached... (TurboDELPHI)
Code: Select all
procedure TForm6.Button1Click(Sender: TObject);
var ip : IProcess;
cnt, noCLcnt: Integer;
cl: string;
begin
stopIt := false; cnt := 0; noCLcnt := 0;
while not stopIt do begin
// I start wordpad.exe as C:\Programmer\Windows NT\Tilbehør\wordpad.exe
ip := Process('wordpad.exe');
if ip.IsStillRunning then begin
cl := ip.CommandLine;
RichEdit1.Lines.Add(intToStr(cnt)+' running: ' + cl);
end ;
if cl='"wordpad.exe"' then begin
RichEdit1.Lines.Add(intToStr(cnt)+'------- ERROR: No command line!!');
inc(noCLcnt);
if noCLcnt>10 then stopIt := True;
end;
inc(cnt);
SendMessage( RichEdit1.Handle, EM_SCROLLCARET, 0, 0);
Application.ProcessMessages; //Not too efficient, but it's just a test
sleep(100);
end;
end;
Code: Select all
...
52 running: "C:\Programmer\Windows NT\Tilbehør\wordpad.exe"
53 running: "C:\Programmer\Windows NT\Tilbehør\wordpad.exe"
54 running: "C:\Programmer\Windows NT\Tilbehør\wordpad.exe"
55 running: "C:\Programmer\Windows NT\Tilbehør\wordpad.exe"
...
Code: Select all
...
30 running: "wordpad.exe"
30------- ERROR: No command line!!
31 running: "wordpad.exe"
31------- ERROR: No command line!!
32 running: "wordpad.exe"
32------- ERROR: No command line!!
...
Stefan