Issue:- While executing the .cmd file from the Command prompt the JAR file runs and hashes the file correctly, but when we use the Dynamics AX to call the .cmd file the JAR file is not executed. The command used was WINAPI::ShellExecute(Command, Parameters);
Investigation :- After preliminary checking from both the AX and command prompt we guessed that the .cmd file was not being executed due to a failure in the calling mechanism. We tried different approaches by calling the cmd.exe and then pass the parameters to mimick the manual approach. But somehow the command prompt opened up but did not execute the JAR file. Then next approach was to add all the commands inside a batch script file which would call the JAR file, so from AX we wouldn't need to specify the details in AX but would just call the batch script file. Still the execution of JAR file from AX was not happening even though we could execute the file manually.
After a lots of Google searches on the execution environment with ample trial and error my colleague identified that the issue was due to JRE execution is the root cause. Meaning that Dynamics AX looks for the Java Runtime under the 32 bit folder(under C:\Program Files (x86)\Java\bin) instead of the 64 bit installed in Windows server 2012 machine. This could be because of the legacy run time approach followed since the older versions executing the JAR files.
Conclusion:-
Install the 32 bit Java runtime on the server.
Notes:
AX job would look something like this to call the WINAPI::ShellExecute(command); where the command = @D:\TestScript.bat
And test script batch file will have,
CD D:\HashFile\
D:\HashFile\HashProgram.cmd parm1 parm2 parm3 parmx....
Another thing to note is to link the batch file to the folder using CD D:\HashFile\ before executing the .cmd file. To point to the correct execution folder before running the command.
Execute exe as a process from X++ X++ run a process with user credentials