Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 91779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:05:00+00:00 2026-05-10T23:05:00+00:00

I have a service that sometimes calls a batch file. The batch file takes

  • 0

I have a service that sometimes calls a batch file. The batch file takes 5-10 seconds to execute:

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 does exist and the code works when I run the same code in-console. However when it runs inside the service, it hangs up at WaitForExit(). I have to kill the batch file from the Process in order to continue. (I am certain the file exists, as I can see it in the processes list.)

How can I fix this hang-up?

Update #1:

Kevin’s code allows me to get output. One of my batch files is still hanging.

‘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 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 does exist and still works outside the service. Any ideas?

Update #2:

Instead of the path of the batch file, I wrote the ‘C:\EnterpriseDB\Postgres\8.3\bin\pg_dump.exe’ for the proc.StartInfo.FileName and added all parameters to proc.StartInfo.Arguments. The results are unchanged, but I see the pg_dump.exe in the process window. Again this only happens inside the service.

Update #3:

I have run the service with a user in the administrator group, to no avail. I restored null for the service’s username and password

Update #4:

I created a simple service to write a trace in the event log and execute a batch file that contains ‘dir’ in it. It will now hang at proc.Start(); – I tried changing the Account from LocalSystem to User and I set the admnistrator user and password, still nothing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:05:01+00:00Added an answer on May 10, 2026 at 11:05 pm

    Here is what i use to execute batch files:

    proc.StartInfo.FileName                 = target; proc.StartInfo.RedirectStandardError    = true; proc.StartInfo.RedirectStandardOutput   = true; proc.StartInfo.UseShellExecute          = false;  proc.Start();  proc.WaitForExit     (         (timeout <= 0)             ? int.MaxValue : timeout * NO_MILLISECONDS_IN_A_SECOND *                 NO_SECONDS_IN_A_MINUTE     );  errorMessage = proc.StandardError.ReadToEnd(); proc.WaitForExit();  outputMessage = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); 

    I don’t know if that will do the trick for you, but I don’t have the problem of it hanging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service that queries data from this json file, but I
We have a service that has some settings that are supported only over net.tcp.
We have a service that runs methods used for data import/export at specified intervals.
I have a service that I am rewriting to use threading. I understand that
I have a service that accepts callbacks from a provider. Motivation : I do
I have a web-service that I will be deploying to dev, staging and production.
I have a web service that I created in C# and a test harness
I have a WCF service that I have to reference from a .net 2.0
We have an external service that is currently accessible via the http (port 80,
I have a PowerShell script that is run automatically when our monitoring service detects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.