Execute from NAV an external program installed in the NAV service

Tomigs
Member Posts: 88
Hi,
In a NAV2016, 3 tier installation, I want to be able to run from NAV an executable that is in a folder in the NAV server. I'm trying using the Wsshell library, as an alternative to the "traditional" Shell function in classic NAV.
When I try to execute it I receive the following error:
A call to System.__ComObject.Run failed with this message: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
It seems to me that my problem is that the code tries to execute the file in the Client machine: I mean it goes to the client machine that is executing it and try to find the program there. But the program is in the service tier. So it returns the program not found error.
Do you concur with this? I mean, does this try to execute things just in the local client?
If so, is there a way to execute them from the NAV service tier instead?
Note: it is an Azzure environment, so I'm not sure if the trick of using a network path starting like this '\\SERVERNAME\' would work, as the client is actually outside the domain.
I'm studying a few links related to this issue, but I haven't been able to address the problem so far.
http://forum.mibuso.com/discussion/44454/shelling-out-problem
http://forum.mibuso.com/discussion/31440/shell-function-in-rtc
In case you want to go through the details, this is what I want to execute: I have a picture in one table, and when clicking into an action, I download the picture, produce a new picture based on this one, using an external tool (ImageMagick) and upload to Live. It errors when trying to execute the Imagemagick part:
\source\IMAGEMAGICK\magick.exe
\source\IMAGEMAGICK\TempImage.jpg -rotate 90
\source\IMAGEMAGICK\TempImage2.jpg
LOCAL funTransformImage(parPicturePerLocation : Record "Location Pictures";parAction : Code[20])
lCompanyInfo.GET;
lCompanyInfo.TESTFIELD(lCompanyInfo."ImageMagick Path");
lImagickExecutable := lCompanyInfo."ImageMagick Path";
//Create a temp blob entry:
lTempBlob.INIT;
parPicturePerLocation.CALCFIELDS(parPicturePerLocation.Picture);
lTempBlob.Blob := parPicturePerLocation.Picture;
lTempBlob.INSERT;
//Then with this TempBlob, export it to the server:
lToFile := lFileMgmt.BLOBExport(lTempBlob,'TempImage.jpg',FALSE);
//GET FOLDER (Just an Experiment, I don't really use this variable)
lPath := PathHelper.GetDirectoryName(lToFile);
//Apply the required rotation to the file
IF parAction = 'ROTATERIGHT' THEN BEGIN
lNewPath := 'D:\source\IMAGEMAGICK\';
IF NOT lFileMgmt.ClientDirectoryExists(lNewPath) THEN BEGIN
lFileMgmt.CreateClientDirectory(lNewPath);
END;
//Copy the temp file to the folder
lFileMgmt.CopyClientFile(lToFile,lNewPath + 'TempImage.jpg',TRUE);
lExecuteThis := lImagickExecutable + ' ' + lNewPath + 'TempImage.jpg' + ' -rotate 90 ' + lNewPath + 'TempImage2.jpg';
// Through automation:
funShellThis(lExecuteThis);
END;
//Introduce a delay so that the system has time to generate the resulting image
SLEEP(1000);
// Upload the file to the BLOB
lNewFile := lFileMgmt.UploadFileSilent(lNewPath + 'TempImage2.jpg');
lTempImportBLOB.INIT;
lFileMgmt.BLOBImportFromServerFile(lTempImportBLOB,lNewFile);
lTempImportBLOB.INSERT;
lTempImportBLOB.CALCFIELDS(lTempImportBLOB.Blob);
parPicturePerLocation.Picture := lTempImportBLOB.Blob;
CurrPage.UPDATE;
parPicturePerLocation.MODIFY;
Being:
LOCAL funShellThis(parCommandLine : Text[1024])
CREATE(wSHShell,FALSE,ISSERVICETIER);
_runModally := FALSE;
dummyint := 1;
wSHShell.Run(parCommandLine,dummyint,_runModally);
CLEAR(wSHShell);
Thanks,
Tomas
In a NAV2016, 3 tier installation, I want to be able to run from NAV an executable that is in a folder in the NAV server. I'm trying using the Wsshell library, as an alternative to the "traditional" Shell function in classic NAV.
When I try to execute it I receive the following error:
A call to System.__ComObject.Run failed with this message: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
It seems to me that my problem is that the code tries to execute the file in the Client machine: I mean it goes to the client machine that is executing it and try to find the program there. But the program is in the service tier. So it returns the program not found error.
Do you concur with this? I mean, does this try to execute things just in the local client?
If so, is there a way to execute them from the NAV service tier instead?
Note: it is an Azzure environment, so I'm not sure if the trick of using a network path starting like this '\\SERVERNAME\' would work, as the client is actually outside the domain.
I'm studying a few links related to this issue, but I haven't been able to address the problem so far.
http://forum.mibuso.com/discussion/44454/shelling-out-problem
http://forum.mibuso.com/discussion/31440/shell-function-in-rtc
In case you want to go through the details, this is what I want to execute: I have a picture in one table, and when clicking into an action, I download the picture, produce a new picture based on this one, using an external tool (ImageMagick) and upload to Live. It errors when trying to execute the Imagemagick part:



LOCAL funTransformImage(parPicturePerLocation : Record "Location Pictures";parAction : Code[20])
lCompanyInfo.GET;
lCompanyInfo.TESTFIELD(lCompanyInfo."ImageMagick Path");
lImagickExecutable := lCompanyInfo."ImageMagick Path";
//Create a temp blob entry:
lTempBlob.INIT;
parPicturePerLocation.CALCFIELDS(parPicturePerLocation.Picture);
lTempBlob.Blob := parPicturePerLocation.Picture;
lTempBlob.INSERT;
//Then with this TempBlob, export it to the server:
lToFile := lFileMgmt.BLOBExport(lTempBlob,'TempImage.jpg',FALSE);
//GET FOLDER (Just an Experiment, I don't really use this variable)
lPath := PathHelper.GetDirectoryName(lToFile);
//Apply the required rotation to the file
IF parAction = 'ROTATERIGHT' THEN BEGIN
lNewPath := 'D:\source\IMAGEMAGICK\';
IF NOT lFileMgmt.ClientDirectoryExists(lNewPath) THEN BEGIN
lFileMgmt.CreateClientDirectory(lNewPath);
END;
//Copy the temp file to the folder
lFileMgmt.CopyClientFile(lToFile,lNewPath + 'TempImage.jpg',TRUE);
lExecuteThis := lImagickExecutable + ' ' + lNewPath + 'TempImage.jpg' + ' -rotate 90 ' + lNewPath + 'TempImage2.jpg';
// Through automation:
funShellThis(lExecuteThis);
END;
//Introduce a delay so that the system has time to generate the resulting image
SLEEP(1000);
// Upload the file to the BLOB
lNewFile := lFileMgmt.UploadFileSilent(lNewPath + 'TempImage2.jpg');
lTempImportBLOB.INIT;
lFileMgmt.BLOBImportFromServerFile(lTempImportBLOB,lNewFile);
lTempImportBLOB.INSERT;
lTempImportBLOB.CALCFIELDS(lTempImportBLOB.Blob);
parPicturePerLocation.Picture := lTempImportBLOB.Blob;
CurrPage.UPDATE;
parPicturePerLocation.MODIFY;
Being:
LOCAL funShellThis(parCommandLine : Text[1024])
CREATE(wSHShell,FALSE,ISSERVICETIER);
_runModally := FALSE;
dummyint := 1;
wSHShell.Run(parCommandLine,dummyint,_runModally);
CLEAR(wSHShell);
Thanks,
Tomas
0
Answers
-
Forget it. Don't even bother with shells and executables anymore. These days you have full .net sensibility.
If you're trying to resize or rotate images, just use a library like https://imageresizing.net/
This will work perfectly.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions