Unity Problem in using C# System.Diagnostics.Process

Hi Unity team,

I am trying to use C# System.Diagnostics.Process to call “Cmd.exe” from Unity script, then fetch all directories using command line(“dir”) and print it on the console.
Please find herewith the code below, this code below works perfectly using Visual Studio 2008 C# “but not with unity c#”. With Unity C# it only prints the command lines we sent, but not the output directories for the command. Any help would be greatly appreciated. Can you please give your input?

void Start () //static void Main(string[ ] args) in VS 2008 C#
{
ProcessStartInfo startInfo = new ProcessStartInfo(“Cmd.exe”);
startInfo.WorkingDirectory = “f:”;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;

Process process = new Process();
process.StartInfo = startInfo;
process.Start();

process.StandardInput.WriteLine(“dir”);
process.StandardInput.Flush();

string line = process.StandardOutput.ReadLine();
while (line != null)
{
UnityEngine.Debug.Log(“line:” + line);
line = process.StandardOutput.ReadLine();
}
process.WaitForExit();
//process.Kill();
}

We are seriously trying to use System.Diagnostics.Process with Unity C#, any help is really appreciated.

Thank you,
Surya.

You have to specify the exact path of the command line program.

I was trying to use a command line program that would normally just work in terminal but it just did nothing, after supplying the exact path it worked.

Thank you Trooper! It works great now…:slight_smile: