Francefire Francefire - 1 month ago 11
C# Question

Run an exe with arguments that come from a text file

As the title says I'm trying to run an EXE with parameters/arguments that come from a TXT file (in ressource) I know how to start a program with arguments but not arguments from a TXT.
This is what I have done but seems to don't work !

private void btnStart_Click(object sender, RoutedEventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat("RustClient.exe"));
startInfo.Arguments = @"Resources\arguments.txt";
startInfo.UseShellExecute = false;
System.Diagnostics.Process.Start(startInfo);
}


It starts the program but without the arguments I put in the txt file.

If I want to read them from a TXT is because I want them to be editable. Basically, my program will be an easy way to edit launch options for guys who don't know them

I'm a very very noob at coding it's my first coding project I have to google everything ^^

Answer

Read argument text first from the file then assign it to arguments

private void btnStart_Click(object sender, RoutedEventArgs e)
    {
        string arg = File.ReadAllText("text file location");
        ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat("RustClient.exe"));
        startInfo.Arguments = arg;
        startInfo.UseShellExecute = false;
        System.Diagnostics.Process.Start(startInfo);
    }