[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Process.Wait not behaving as expected


On Thu, 1 Jan 2026 at 17:22, Lee <t.lee.davidson@xxxxxxxxx> wrote:

> I am shelling out to a command for which I need to catch any error message
> and the exit code.
>
> I can't use Process.Wait without a timeout as it is a server and my
> project application would hang forever. However, when I use
> .Wait with any value other than 0, the exit code is not correctly set in
> Process.Value.
>
> Am I misunderstanding how Process.Wait should work, or is this unintended
> behavior?
>
> Demo project attached.
>
>
> --
> Lee


I think doing it that way maybe $hProc is dead by the time you check it?

You can get the value okay in Process_Kill

Public Sub Proc_Kill()

  Debug Last.Value

End

It's hard to tell what exactly happens here.
If i use the following code in your program...

Public Sub Button1_Click()

  $hProc = Shell System.Shell & " " & Application.Path &/ "main.sh" For
Read As "Proc"
  $hProc.Wait(SpinBox1.Value)
  Debug $hProc.Value

End

Public Sub Proc_Kill()

  Debug $hProc.Value

End

a Wait time of 0 gives this..
FMain.Proc_Kill.16: 3
FMain.Button1_Click.10: 3

Using any other value gives this ...
FMain.Button1_Click.10: 0
FMain.Proc_Kill.16: 3

In both cases Proc_Kill reports correctly but if any wait time is given the
Click event comes first and $hProc.Value seems to be zero.

Respects
BruceS

References:
Process.Wait not behaving as expectedLee <t.lee.davidson@xxxxxxxxx>