Execute from NAV an external program installed in the NAV service

TomigsTomigs Member Posts: 86
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:
D:\source\IMAGEMAGICK\magick.exe D:\source\IMAGEMAGICK\TempImage.jpg -rotate 90 D:\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

Answers

  • EvREvR Member Posts: 178
    edited 2017-01-13
    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.
Sign In or Register to comment.