Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to launch external processes/servers during startup or later, and automatic shutdown of these processes when app exits #163

Open
GoogleCodeExporter opened this issue Aug 28, 2015 · 8 comments

Comments

@GoogleCodeExporter
Copy link

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

@GoogleCodeExporter
Copy link
Author

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

@cztomczak
Copy link
Owner

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").

@bkris
Copy link

bkris commented Oct 31, 2017

Somebody knows something about this feature? Is this planned to be implemented or already does?

@cztomczak
Copy link
Owner

There is no known schedule for implementing this feature.

@cztomczak
Copy link
Owner

This functionality can be accomplished using NirCmd command-line utility, see:

  1. 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

  2. Example code for shutdown using "waitprocess" command in NirCmd: An option in settings.json to specify a path to a script or exe that will be executed when application shuts down #186 (comment)

@jal617b
Copy link

jal617b commented May 18, 2020

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.

@avega93
Copy link

avega93 commented Aug 26, 2020

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.

@darkterminal
Copy link

I have pull example how to create Windows Print Service on start up and on shutdown application just feel free to take a look #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants