IMatch.processRun - not working for me...

Started by Jingo, September 16, 2019, 12:12:28 AM

Previous topic - Next topic

Jingo

Hi Mario - I have an app I'm working on that relies upon an external script to do some work (easy to figure out from the code below)... I've tried both a cmd.exe (with params) and a BAT file call and they both fail to run via IMatch (and via Firefox browser).. yet, the command line works directly in a cmd window and the bat file works perfectly running it directly.  Any thoughts/guidance?


$('#btn-ftp').click(function(e) {
    $('#perf-info').text('');
    IMatch.processRun({
        executable: 'ftp.bat',
        showwindow: true,
        timeout: 20
    }).then(function(response) {
        if (response.result == 'ok') {
            console.log(response.output);
        } else {
            console.log(JSON.stringify(response, null, 2));
        }
    });
});


I've also tried:


$('#btn-ftp').click(function(e) {
    $('#perf-info').text('');
    IMatch.processRun({
        executable: 'cmd.exe,
        //parameters : '/C "C:/Program Files (x86)/WinSCP/WinSCP.exe" ftp://ftpinfohere "C:/Program Files (x86)/WinSCP/WinSCP.exe" /ini=nul /script="C:/ProgramData/photools.com/imatch6/webroot/user/Gallery/ftp.txt"',
        showwindow: false,
        timeout: 20
    }).then(function(response) {
        if (response.result == 'ok') {
            console.log(response.output);
        } else {
            console.log(JSON.stringify(response, null, 2));
        }
    });
});


When I run the Bat file, the header/response gives results but the bat file doesn't appear to launch because the console window doesn't appear. 

Header/response info is:

Network Params:
executable   ftp.bat
showwindow   true
timeout   20
auth_token   

Network Response:
{"result":"ok","exitCode":2,"output":"","errorOutput":""}


Thanks! - Andy.

Mario

Check the console output on the browser debugger (look at the response in detail). This usually just works.
In your second example you just run cmd.exe, without any parameters (commented out).
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Quote from: Mario on September 16, 2019, 12:35:19 AM
Check the console output on the browser debugger (look at the response in detail). This usually just works.
In your second example you just run cmd.exe, without any parameters (commented out).

Sorry.. that wasn't commented out when I ran it for real... nothing shows in the console output for the browser.. looks like it works - but the commands just don't execute...

Mario

Use the sample app for processes. Does it work? If so, try substituting your command line with one of the examples. if this fails, the problem is your command or the software you are trying to run.
I have used this successfully to run many things, from ExifTool to PowerShell to git.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Quote from: Mario on September 16, 2019, 12:44:07 AM
Use the sample app for processes. Does it work? If so, try substituting your command line with one of the examples. if this fails, the problem is your command or the software you are trying to run.
I have used this successfully to run many things, from ExifTool to PowerShell to git.

Sorry Mario.. I figured out the bat file issue in any event... I didn't specific the explicit path to the file erronously thinking the apps working "directory" would be the default starting place.  It works PERFECTLY now.. and I'm a bit giddy to get this app finished and shared (I'm not sure anyone will use it.. but it has been fun to get it up and running).

Thx for the nudge and confirmation I was calling it correctly!  - Andy.

Corrected code:


IMatch.processRun({
                executable: 'C:/ProgramData/photools.com/imatch6/webroot/user/Gallery/ftp.bat',
                showwindow: true,
                timeout: 20
            }).then(function(response) {

Mario

#5
processRun does not have a parameter to set the 'working directory' like shellExecute. This is because both methods work completely differently internally.
shellExecute runs a command in the same fashion you would run it on the command line, including the "working dir" you can set.
procesRun starts a process under the control of IMatch (and hence your app) so you can control it and pipe the shell output back into your app for processing.

Unless you include the full path or the command you run is in the "Path", it won't work. ExitCode 2 means "Path not found".
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Thx Mario.. makes sense and works perfectly now.  Many thx!!