Discussions related to Visual Prolog
daveplummermd
VIP Member
Posts: 75
Joined: 18 Jul 2006 17:18

useEXE question

Unread post by daveplummermd »

Is it possible to detect the termination of a process/program that is launched by useExe ?

1) I have this code for the creation of useExe oject and program launch:

Code: Select all

         ...         CommandLine = "C:\\Users\\Owner\\AppData\\Local\\Logseq\\logseq.exe",         RunObj = useExe::new(CommandLine),         RunObj:run(),         retractAll(logseRunObj(_)),         assert(logseRunObj(RunObj)),
So I have access to the useExe object.

2) Now if I terminate the external program using the program's usual exit, is there some state of the useExe obect I can use to detect that termination?

example of failing; this does not work:

Code: Select all

 onPushButton1Click(_Source) = button::defaultAction :-         logseRunObj(Obj),         Obj:isActive(),         stdio::write("\nYes"),         !.     onPushButton1Click(_Source) = button::defaultAction :-         stdio::write("\nNo"),         !.
thanks in advance
Dave
Dave Plummer
User avatar
Thomas Linder Puls
VIP Member
Posts: 1318
Joined: 28 Feb 2000 0:01

Re: useEXE question

Unread post by Thomas Linder Puls »

Yes, a useExe object is a syncObject:

Code: Select all

interface useExe supports syncObject ...
This particular syncObject will be "signaled" when the subprocess is complete and "unsignaled" while it runs.

You have to wait for the syncObject to become signaled:

Code: Select all

predicates     wait : ().     wait : (unsigned Milliseconds = multiThread_native::infinite_timeout) -> unsigned EventCode.     % @short Suspends thread's execution until the object state to become signaled or time interval to elapse.     % @detail The thread enters the wait state. The return value #EventCode specifies one of the following:<br>     % multiThread_native::wait_abandoned - only for mutex synchronization object: mutex was not released before the owning thread terminated.     % The ownership of mutex  is granted to the calling thread, and the mutex is set to nonsignaled. <br>     % multiThread_native::wait_object_0 - the state of synchronization object is signaled.<br>     % multiThread_native::wait_timeout - the time interval Milliseconds elapsed,  and the object stayed in nonsignaled state.<br>     % @exception nativeCallException is raised if internal API function call failed     % @end   predicates     tryWait : (unsigned Milliseconds) determ.     % @short Succeeds if the state becomes signaled before the timeout #Milliseconds (default infinite wait) expires.     % @exception nativeCallException is raised if internal API function call failed     % @end
To "poll" rather than doing a blocking wait you should use tryWait.
Regards Thomas Linder Puls
PDC
daveplummermd
VIP Member
Posts: 75
Joined: 18 Jul 2006 17:18

Re: useEXE question

Unread post by daveplummermd »

Thanks, and I am encouraged but confused.
I don't know what it means to be "signaled" or "unsignaled".

I have drilled into the syncObject created by useExe and closely examined the "wait" type functions with the debug. However, I do not see a way the calling obect ("form.frm") receives an event or notice that can trigger an action. (I have tried many combination of wait(), wait(Millisecs) and trywait()).

What am I missing.
Thanks for your response
Dave
Dave Plummer
User avatar
Thomas Linder Puls
VIP Member
Posts: 1318
Joined: 28 Feb 2000 0:01

Re: useEXE question

Unread post by Thomas Linder Puls »

In some cases programs simply launch other programs and then exit. Our IDE for example examines if there is already an IDE with the same project open, if that is the case the it puts focus to that IDE and exits.
Likewise, Notepad++ (controlled by a setting) will switch to an already opened.

If you have Notepad++ installed you can try this little program:

Code: Select all

implement main     open core, stdio   clauses     run() :-         E = useExe::new(@"C:\Program Files\Notepad++\notepad++.exe"),         E:run(),         foreach _ = std::cIterate(10) do             multiThread_native::sleep(100),             writef("%\n", toBoolean(E:isActive()))         end foreach.   end implement main   goal     console::runUtf8(main::run).
With and without Notepad++ already running.


Regarding "signaled". There are a number of syncObjects: mutex, criticalSection, event ... and useExe. Signalled means something different for each of these. For useExe it means terminated.
Regards Thomas Linder Puls
PDC
daveplummermd
VIP Member
Posts: 75
Joined: 18 Jul 2006 17:18

Re: useEXE question

Unread post by daveplummermd »

Excellent. This provides me with a way to solve what I am stuck on. It is exactly what I am looking for.
Thanks!
Dae
Dave Plummer
Post Reply