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

  • SEARCH
  • Home
  • 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

We have a .Net 3.5 Workflow hosted as a service that sometimes stops unexpectedly.
I have a service that also contains an activity the problem is sometimes it
I have a WCF based service that I use to expose AJAX functionality. Sometimes
I have a service that is downloading a file. When the download is done,
I have a WCF service that sometimes has to return a Fault. For some
We have a web service coded in C# that makes many calls to MS
I have a service that does database calls. The service receives a request with
I have a background service that sometimes gets killed by the OS when it
I have a service that I would like it to become single instance, because
I have .Net service that listens on single port over TCP protocol. Clients connect

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.