Ran
Ran

Reputation: 725

run a .exe file with argument from unity c#

I want to run a .exe file with argument from unity using C#, I saw a lot of tutorials and I tried a lot of instructions and this is what I came up with so far:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = "C://PATH//ABC.exe";
startInfo.Arguments = "ARGUMENT";

The argument should create a text file, but nothing is happening, and there is no error. Can anyone tell me why is the text file not creating.

Upvotes: 2

Views: 3144

Answers (1)

Ahmad Khan
Ahmad Khan

Reputation: 2703

This wouldn't start the process. You need to set the StartInfo of the process, and then start the process.

// Create a process
System.Diagnostics.Process process = new System.Diagnostics.Process();

// Set the StartInfo of process
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.StartInfo.FileName = "C://PATH//ABC.exe";
process.StartInfo.Arguments = "ARGUMENT";

// Start the process
process.Start();
process.WaitForExit();

Upvotes: 2

Related Questions