I have a command line executable I wrote that essentially executes a batch file. This batch file makes a call to another executable and redirects its output to a text file called “out.txt”. when its done, my program then reads that file and prints it to standard output (printf). When run from the command line, this works just fine. This is under windows using cmd.exe.
However, when I run this executable from my Unity app, the “out.txt” file never gets created so nothing gets printed and Unity captures no output from the program. Here is how I’m invoking my command line program:
try
{
ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = Application.persistentDataPath + "/fetchrefdata.exe",
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
Arguments = refTemplateString
};
Process myProcess = new Process
{
StartInfo = startInfo
};
myProcess.Start();
string output = myProcess.StandardOutput.ReadToEnd();
UnityEngine.Debug.Log(output);
myProcess.WaitForExit();
int i = 0;
}
catch (Exception e)
{
print(e);
}
Now, I know the command line program is getting executed because changing it to just print “Hello World” works and Unity captures that string. But when running the regular command line program, the redirect in the batch file it calls never happens even when given an explicit path for the redirect output file. Again, this command line program works flawlessly when manually run from the command line.
The batch file that gets called by the command line program is essentially just this:
ECHO OFF
reftool.exe [a bunch of arguments] > out.txt
Can anyone shed light on this issue? It’s driving me bonkers.