Check if process exists

Started by Carlo Didier, September 10, 2019, 09:49:17 AM

Previous topic - Next topic

Carlo Didier

Does anyone know how to check from an iMatch/javascript script if a certain process is already running?
Something like this from powershell:
Get-Process "Notepad"

Mario

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.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Quote from: Mario on September 10, 2019, 11:02:05 AMIMatch 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

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.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Quote from: Mario 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.
Quite convoluted, if it worked.
At least this
            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
{"result":"ok"}
as a result ...

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

Mario

#5
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.


                    IMatch.processRun({
                        'executable' : 'cmd.exe',
                        'parameters' : '/C tasklist',
                        'showwindow' : false,
                        'timeout' : 30

also works just fine in that app. Line 86ff.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Got it working. Didn't realize I had to check response.output.
Thanks!

Carlo Didier

FYI, I called tasklist.exe directly. No need to go through "cmd.exe /C tasklist".

Mario

Quote from: Carlo Didier on September 10, 2019, 04:21:46 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.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook