codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Run an External Executable in ASP.NET Core

How to execute an external program by calling an API endpoint.

Changhui Xu
codeburst
Published in
4 min readOct 4, 2019

Sometimes our application needs to allow users to execute an external program by calling an API endpoint. The external program could be a script, a third-party software, or an executable written in an outdated framework.

In order to trigger a background process that cannot be easily integrated in the modern framework or infrastructure, generally we want to decouple the systems. For instance, we can let our system delegate the external process to a job management agent, e.g., Jenkins. Another common approach is to fire a command in a message queue, then the external executable subscribes the event and takes actions accordingly.

Life happens. When we are not able to afford to spin up a set of infrastructure, we have to let our application call a command line interface directly. This post will go over an example use case that a helloworld.exe (in Windows) is executed from an ASP.NET Core Web API endpoint. This solution might need to be slightly modified if your application works in another OS. The full solution can be found in this GitHub repository.

Show me the code

We first create a contrived program called helloworld.exe in .NET framework. This helloworld.exe simulates the external program that will be triggered by an ASP.NET Core Web API project. This program, see the code snippet below, simply writes some logs to the Console and creates a file on disk.

We build the project to generate a helloworld.exe file and we know its location.

Then we create a bare-bones ASP.NET Core Web API project. For demo purposes, we modify the Get(int id) action method in ValuesController class to be the following.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Changhui Xu

Lead Application Developer. MBA. I write blogs about .NET, Angular, JavaScript/TypeScript, Docker, AWS, DDD, and many others.

Responses (3)

Write a response