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)

Call exe file in AX 2009 batch job

(0) ShareShare
ReportReport
Posted on by

I have a job calling external exe file for C# console application and this is working fine on the client side. I scheduled this job to run over night on the server and AX job is running correctly as per the resulted log but the exe is not called and I guess that because there is no user logged in at that time. Please help how can I make it called successfully to complete the required task?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You most likely have used WinAPI::shellExecute to run the file, and that is a client-bound process. Batch jobs are running server-side, for which you have the WinAPIServer class.

    This has already been documented, along with the solution:

    blogs.msdn.microsoft.com/.../how-to-execute-an-external-process-from-a-batch

    Please mark the answer with the checkbox to verify and resolve the topic.

  • Community Member Profile Picture
    on at

    Unfortunately, it doesn't work.

  • Vilmos Kintera Profile Picture
    46,149 on at

    Explain what you did and what does not work, since my remote mind-reading capabilities are very limited :)

    Also explain what did you try to make it work, i.e. following the instructions on the error messages, debugging and stepping through the code to identify which part of the process might be incorrect, etc.

  • Community Member Profile Picture
    on at

    Here is the code to be run on the batch running on the server over night

    public void run()

    {

       int i = 0, j =0;

       System.Diagnostics.Process              process;

       System.Diagnostics.ProcessStartInfo     processStartInfo;

       ;

       info("Export has been completed!");

       if(ConsumeAXWS::write2eCODA())

           info("Entries has been moved to eCODA!");

       i = WinAPI::shellExecute("C:\\AX2eCODA\\AX2eCODA\\bin\\Debug\\AX2eCODA.exe");

       if(i == 0)

       {

           //info("Exe didn't run");

           new InteropPermission(InteropKind::ClrInterop).assert();

           process = new System.Diagnostics.Process();

           processStartInfo = new System.Diagnostics.ProcessStartInfo();

           processStartInfo.set_FileName("C:\\AX2eCODA\\AX2eCODA\\bin\\Debug\\AX2eCODA.exe");

           process.set_StartInfo(processStartInfo);

           process.Start();

           process.WaitForExit();

           info("Exe ran server side");

       }

       else

           info("Exe ran client side");

    }

    The program to be called is configured to write a log whenever it is called but here the program is not called with the batch.

    I hope I'm clear now :)

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    I think execution stops at WinAPI since you are still calling a client-bound process server side. Comment that out and do CIL.

    Also, do you have that executable available in the folder on the AX AOS instance that is acting as batch server? You could simply verify that https://community.dynamics.com/ax/b/faisalfareedaxlibrary/archive/2016/01/10/ax-2012-file-existance-check

    Using a try-catch block to catch any errors would be useful too:

    [View:https://msdn.microsoft.com/en-us/library/ee677495.aspx:750:50]

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

    You're still using WinAPI::shellExecute(), even after Vilmos explained why it can't work. Get rid of it.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Please refer the following:

    (How to execute an external process from a batch)

    blogs.msdn.microsoft.com/.../how-to-execute-an-external-process-from-a-batch

    Community Discussion thread:

    (Shell execute in server)

    community.dynamics.com/.../143239

  • Community Member Profile Picture
    on at

    I did what all of you advised and it didn't give errors but also the exe seems like not running; it doesn't take the usual action of its execution.

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans