Author Topic: Check if process exists  (Read 88 times)

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1306
Check if process exists
« on: September 10, 2019, 09:49:17 AM »
Does anyone know how to check from an iMatch/javascript script if a certain process is already running?
Something like this from powershell:
Code: [Select]
Get-Process "Notepad"

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 22794
Re: Check if process exists
« Reply #1 on: September 10, 2019, 11:02:05 AM »
IMatch has no features for this. And browsers cannot access this kind of information (for very good security reasons).
If you really need to do such things from an IMatch App (???) you can run a PowerShell script and pipe the results back into your app.
See the ProcessControl app examples.

Or just write the whole thing in PowerShell or Python or C# or whatever. If you need to access other processes from your app, chances are that a normal IMatch App written in JavaScript is probably not what you really want here. I would write such a thing in PowerShell or Python, accessing IMatch data via IMWS as needed.

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1306
Re: Check if process exists
« Reply #2 on: September 10, 2019, 11:30:32 AM »
IMatch has no features for this. And browsers cannot access this kind of information (for very good security reasons).
I thought so, but I hoped that somehow as the script was running in iMatch it would be possible (again, this was no issue with the old iMatch scripting engine).

It's not a big issue and I'd like to explain when it would be nice to have: Some applications, if you start them from a script, create a new instance if one is already running. If you don't want that, you would first check for it and then call it another way.
As I said, a special case and not important.

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 22794
Re: Check if process exists
« Reply #3 on: September 10, 2019, 12:06:22 PM »
Cal Get-Process from your app and react depending on the result. Running PowerShell scripts or other commands is easily doable via the Process endpoints.

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1306
Re: Check if process exists
« Reply #4 on: September 10, 2019, 03:08:38 PM »
Cal Get-Process from your app and react depending on the result. Running PowerShell scripts or other commands is easily doable via the Process endpoints.
Quite convoluted, if it worked.
At least this
Code: [Select]
            IMatch.shellExecute({
'executable' : '\""C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"\"',
'parameters' : '-command {get-process}',
'showwindow' : true
    }).then(function(response) {
                    console.log(JSON.stringify(response));
                });
only gives me
Code: [Select]
{"result":"ok"}as a result ...

Same for
Code: [Select]
            IMatch.shellExecute({
'executable' : '\"cmd.exe\"',
'parameters' : '/C tasklist',
'showwindow' : true
    }).then(function(response) {
                    console.log(JSON.stringify(response));
                });

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 22794
Re: Check if process exists
« Reply #5 on: September 10, 2019, 03:28:22 PM »
Please look again at the Processes sample app I mentioned. It shows how to run an external command, wait for it to complete and then display the console output.
Just click on the "Run systeminfo" button in that app, and then check the corresponding code. This should display the output of the command line application. Just checked. Works a treat.

 
Code: [Select]
                    IMatch.processRun({
                        'executable' : 'cmd.exe',
                        'parameters' : '/C tasklist',
                        'showwindow' : false,
                        'timeout' : 30
also works just fine in that app. Line 86ff.
« Last Edit: September 10, 2019, 03:32:03 PM by Mario »

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1306
Re: Check if process exists
« Reply #6 on: September 10, 2019, 04:21:46 PM »
Got it working. Didn't realize I had to check response.output.
Thanks!

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1306
Re: Check if process exists
« Reply #7 on: September 10, 2019, 04:24:14 PM »
FYI, I called tasklist.exe directly. No need to go through "cmd.exe /C tasklist".

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 22794
Re: Check if process exists
« Reply #8 on: September 10, 2019, 04:29:35 PM »
Got it working. Didn't realize I had to check response.output.
Thanks!

Run your apps in the web browser while working on them. The "Network tab" shows you the payload IMWS endpoints return.