I am trying to call an application with simple code like
public void Run(string command)
{
Process proc = new Process();
proc.StartInfo.FileName = "acvTemp.exe";
proc.StartInfo.Arguments = command;
proc.Start();
proc.WaitForExit();
}
The fileName process I am launching actually spawns a new window. Its being launched with some commands that make it no exit . I.e
command = acvtest.exe /launch /wait /log:<temp.log>
So acvtest.exe starts running on the machine and is actually is still running so I could run other commands like
acvtest.exe /getid:<name>
This is how I will manually use the application.
acvtest.exe /launch /wait /log:<temp.log>
acvtest.exe /getid:<name>
Note the actual /launch process return to shell command prompt, because with /launch a new command window is opened and output of /getid is actually written to the log.
My problem is when the first /launch or /getid commands run, waitforexit() seems to be exiting even before the handle is released on log. (may be before some child thred exits?)
I.e the following command fails until I put some sleep or wait in between. even with waitforexit()
Run("/launch /wait /log:<temp.log>");
Run("/getid:<name>");
Run("shutdown");
//Needs some sleep or wait here
using (StreamReader reader = new StreamReader("temp.log"))
{
Console.WriteLine(reader.ReadToEnd());
}
Without any sleep or wait between the above two sections, accessing the log fails with error that it is already being used by another process. Looks like the application is exiting even before it actually finishes its processes. Is this a problem with teh application? Anything I can do to work around it?
I am suspecting I may need some differt Run() code here because a new shell is launched.
[update]
The problem is not just with the log file. When I am runnning Run("/getid:") on say some 100,000 file names, many of these are failing with 'resources not available' error, which is why I thought the application may be exiting even before its releasing its resources Thanks for looking.