web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to run an .exe file from AX?

(0) ShareShare
ReportReport
Posted on by 1,385

Hi Friends,

Can anyone tell, how I can run an .exe file in a specified folder from AX? On running that .exe file, it sends a text file (input.txt) and receives another text file (output.txt) from an website.

Also, how I can import few specified columns from the output.txt file to the AX table?

Note: Text files are with fixed field length.

Thanks,

Aarvi

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rachit Profile Picture
    4,015 User Group Leader on at

    Hi Aarvi,

    AX has built in classes to perform windows API functions, have a look at WinAPI class, you can use shellExecute method of WINAPI class to run an .exe file.

    For more information on this refer to this very nice blog:

    dynamics-ax.blogspot.com.au/.../winapishellexecute-method.html

    Be aware that WinAPI class runs on client so if u try to use this inside some batch process then  you may need to assert the permissions. [refer to winAPIServer class]

    Regarding reading columns from .txt files, you can use IO classes, refer msdn.microsoft.com/.../cc967403.aspx for more details.

    Hope this helps.

    Thanks,

    Rachit Garg

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Another option is the System.Diagnostic.Process class - you can use it directly in X++ via .NET Interop, or create a .NET wrapper class (that's useful especially if you want to do a bit more complex things, such as handling events).

  • Suggested answer
    Community Member Profile Picture
    on at

    Use following WINAPI method to execute your exe file

    winapi::shellExecute("notepad");

    WinAPI::shellExecute(

       Filename    _lpFile,

       str         _lpParameters      = '',

       str         _lpDirectory       = '',

       str         _lpOperation       = #ShellExeOpen,

       int         _show              = #SW_SHOWNORMAL,

       boolean     _waitForCompletion = false

       )

  • arviax Profile Picture
    1,385 on at

    Thanks Martin and Rachit for your response. Your tips really helped  me a lot !

    Aarvi.

  • arviax Profile Picture
    1,385 on at

    Hi Nitesh,

    I have one more clarification to be made. I have an file named rece1.exe file in the folder path: D:\AX\Test\

    When I tried to call that rece1.exe file from AX, I am getting the below error: "Windows cannot find 'rece1.exe'. Make sure you typed the name correctly, and then try again. ".

    I gave the correct name, but still it is showing this error. Could you please correct me where I am going wrong?

    Thanks,

    Aarvi.

  • dolee Profile Picture
    11,279 on at

    Hi Aarvi,

    Check if you specify the path for your executable in one of the following ways:

    path = "D:\\AX\\Test\\rece1.exe";

    or

    path = @"D:\AX\Test\rece1.exe"

    Regards,

    Dominic

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Aarvi,

    Please follow Dominic...

    that is the solution, Please validate

  • arviax Profile Picture
    1,385 on at

    Hi Dominic,

    Thanks a lot for your response. I tried with the below 3 ways.

    1. WinAPI::shellExecute("rece1.exe",@"D:\AX\Test","D:\\","",1);

    2. WinAPI::shellExecute("rece1.exe","D:\\AX\\Test","D:\\","",1);

    3. WinAPI::shellExecute("rece1.exe","D:\AX\Test","D:\\","",1);

    But still I am getting the same error.

    Thanks,

    Aarvi.

  • dolee Profile Picture
    11,279 on at

    Hi Aarvi,

    Try WinAPI::shellExecute(@"D:\AX\Test\rece1.exe");

    Also, it looks like you have put the path value at the "parameter" parameter spot. And have "D:\\" as the path instead.  (msdn.microsoft.com/.../winapi.shellexecute.aspx)

    Maybe that's why it's not working.

    Regards,

    Dominic

  • arviax Profile Picture
    1,385 on at

    Hi Dominic,

    It worked !! :-) Thanks a lot for your kind favor.

    Also, I would like to thanks Martin and Nitesh for their replies.

    Regards,

    Aarvi.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans