I am developing Windows Service which will generate csv file through batch file.Later I will read the file. Below is the batch file command psexec \wksp000ae2c8 -h -w D:\UPSData\OCCG\OPMI\Cache\OPSTimingExtractor\ "C:\Program Files (x86)\UPSAPPS\OCCG\OPMI\Tools\dirt.bat" > 051120072244.091.csv
I am able to generate to the csv file when I execute in Console individually. The Windows Service generates batch file.
But when I execute it as windows Service Process.WaitForExit does not return.
I individually double click the batch file it executes and generates the batch file . Below is the code
Process procstart = new Process();
ProcessStartInfo psi = new ProcessStartInfo
{
CreateNoWindow = true,
UseShellExecute = false,
FileName = "cmd.exe",
Arguments = @"/C "+ BatfileName,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
RedirectStandardError = true,
ErrorDialog = false
};
procstart.StartInfo = psi;
procstart.Start();
procstart.WaitForExit();
When I add procstart.Kill or Close it does not work. When I go to location and try to open the file it says FIle is in another process.
When I try to delete the file it says "The action cannot be completed because the file is in open in cmd.exe