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();
}