Open GoogleCodeExporter opened 9 years ago
It is possible to close external processes currently, but only with some additional .bat script and WMI queries. This has been explained here: https://groups.google.com/d/msg/phpdesktop/PLC0dMz0Pp8/6kCC_VNTP_wJ
Such .bat script would check whether phpdesktop.exe process still runs and when it's not running anymore it could end external processes launched by php's system() command. It's a bit complicated, but feasible. Your app's processes names shold be unique to make it reliable.
Original comment by czarek.t...@gmail.com
on 7 Mar 2015 at 8:43
Related: Issue #186 ("An option in settings.json to specify a path to a script or exe that will be executed when application shuts down").
Somebody knows something about this feature? Is this planned to be implemented or already does?
There is no known schedule for implementing this feature.
This functionality can be accomplished using NirCmd command-line utility, see:
NirCmd utility and its various exec commands: https://github.com/cztomczak/phpdesktop/wiki/Knowledge-Base#how-do-i-call-external-programs-or-commands-asynchronously-in-background-without-waiting-for-them-to-end
Example code for shutdown using "waitprocess" command in NirCmd: https://github.com/cztomczak/phpdesktop/issues/186#issuecomment-376860052
Another option is to use a script (Autohotkey or AutoIt etc) to create an app launcher.
ApplicationFolder |AppLauncher.ahk // this can be compiled to .exe | phpdesktopfolder |__phpdesktop-chrome.exe
Contents of AppLauncher.ahk
Run, notepad.exe // whatever app you want to run
Run, phpdesktopfolder\phpdesktop-chrome.exe
WinSetTitle, PhpDesktop App //main_window title of your phpdesktop app based on settings.json
WinWait, PhpDesktop App //wait until your app is closed
WinWaitClose
Process, Close, notepad.exe
MsgBox, Notepad is now closed.
A solution that worked for me is to set the port on "listen_on" option dynamically, in the first page of the app run a ".bat" file that close all process that I created before, in my case python.exe process. After this, create the process that you need. But this only works to prevent crash on re-open. Not kill all the process after close. Sorry for my bad english.
I have pull example how to create Windows Print Service on start up and on shutdown application just feel free to take a look https://github.com/cztomczak/phpdesktop/pull/305 maybe it's help you to know how it's work for me. I forgot to write settings.json value listen_on
with fixed value in README.md example.
User can execute applications using php's system() command or similar, but there is no easy way to end long running processes when phpdesktop application closes.
Option 1 - "execute_on_startup" in settings.json
User wants to run node.js server along with phpdesktop. That server should start when phpdesktop starts and shut down automatically when phpdesktop app exits.
Solution: In settings.json add option "execute_on_startup" which would be a list of .exe, allowed would be relative paths (phpdesktop dir) or full paths.
There is also an idea for "execute_on_shutdown" option, see Issue #186.
Option 2 - new JS API: phpdesktop.LaunchProcess()
While app runs user wants to run an external process. Currently this can be done using XMLHttpRequest to a php script that calls php's system() command or similar. Unfortunately there is no easy way to end this process when phpdesktop app exits. For example this process runs a long task, but user exits application early, so this process should be killed automatically.
Solution: Add new function to JavascriptApi: LaunchProcess(). It should have some options whether the app window should be hidden. Use the ShellExecuteEx function and save process handle (SHELLEXECUTEINFO.hProcess) for later to end the process when app exits.
ShellExecuteEx: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762154(v=vs.85).aspx
SHELLEXECUTEINFO: https://msdn.microsoft.com/en-us/library/windows/desktop/bb759784(v=vs.85).aspx
Original issue reported on code.google.com by
czarek.t...@gmail.com
on 7 Mar 2015 at 8:34