I have a service that call a batch file sometime. The batch file take 5-10 seconds to be executed.
The code to launch the batch file is :
System.Diagnostics.Process proc = new System.Diagnostics.Process(); // Declare New Process
proc.StartInfo.FileName = fileName;
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
The file really exist and the code work when I run the same code in Console. When it runs in the service the service hang at the WaitForExit(). I have to kill the batch file from the Process to be able to continue (So I am sure the file exist, I see it in the processes list).
How can I fix that?
Update #1:
Kevin code gave me the possibility to get some output. One of my batch file still hang.
"C:\EnterpriseDB\Postgres\8.3\bin\pg_dump.exe" -i -h localhost -p 5432 -U postgres -F p -a -D -v -f "c:\backupcasecocher\backupdateevent2008.sql" -t "\"public\".\"dateevent\"" "DbTest"
the other batch file simplify is:
"C:\EnterpriseDB\Postgres\8.3\bin\vacuumdb.exe" -U postgres -d DbTest
I have checked the path and the postgresql path is fine. THe output directory exist... and it works outside the service. Any idea?
Update #2:
Instead of the path of the batch file, I have wrote the "C:\EnterpriseDB\Postgres\8.3\bin\pg_dump.exe" for the proc.StartInfo.FileName
and i have add all parameters too proc.StartInfo.Arguments
. I have the same result : hang. But, I see the pg_dump.exe to the process windows... this is just happening in service...
Update #3:
I have run the service with a user that is in the group of administrator and it does not help the situation. I put back null for password and username of the service.
Update #4:
I have create a simple service that simply right in the event log some trace and execute a batch file that contain "dir" in it. It still hang at proc.Start(); I have change the Account from LocalSystem to User and I have set the admnistrator user and password. It still hang.