18.2. Executing External Applications
Problem
You need to run an external application from your web application to perform a required operation.
Solution
Use the System.Diagnostics.Process.Start method to
call your external application.
In the code-behind class for the page, use the .NET language of your choice to:
Import the
System.Diagnosticsnamespace.Create a
ProcessStartInfoobject, passing the name of the external application to run along with any required command-line parameters.Set the working directory to the location of the external application.
Start the external application process by calling the
Startmethod of theProcessclass, passing theProcessStartInfoobject.
Example 18-3 and Example 18-4 show the relevant portion of the sample VB and C# code-behind files that illustrate this solution.
Discussion
Applications frequently must interface with other applications or systems that use different technologies. At the same time, it is not always practical to migrate these applications to the new platforms or to provide web service wrappers to gain access to the applications. Sometimes, the only practical solution is to execute another program to perform the required operation. For example, you may have an existing application that exports data from your Cobol accounting program to a format usable by other systems. The common language runtime (CLR) provides a set of classes to support running other applications from within the .NET environment. These classes are part of the
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access