Home >Backend Development >C++ >How Do I Specify the Default Directory for a Process in .NET?
Controlling the Startup Directory of External Processes in .NET
Launching external applications, like Java programs, from a C# .NET console application often requires setting the process's initial working directory. This is crucial for applications that depend on resources located in a specific folder.
The Solution:
The WorkingDirectory
property of the ProcessStartInfo
class provides the solution. This property lets you define the starting directory for the new process.
Illustrative Example:
<code class="language-csharp">... using System.Diagnostics; ... var processInfo = new ProcessStartInfo(); processInfo.WorkingDirectory = @"C:\MyApplicationDirectory"; // Set the working directory // Configure other process properties... Process process = Process.Start(processInfo);</code>
In this code, WorkingDirectory
is set to C:MyApplicationDirectory
. The launched process will use this as its default directory. Replace this path with the actual directory containing your application's support files.
By setting the working directory, you guarantee the launched process can access required files and function correctly.
The above is the detailed content of How Do I Specify the Default Directory for a Process in .NET?. For more information, please follow other related articles on the PHP Chinese website!