after I was kicked from one forum - where should i ask this? RRS feed

  • Question

  • Hello all,


    I was asked to make some changes in a code that was written and worked fine.

    basically the code creates a script for each machine and a main script to run all the scripts on each machine using Psexec. The main script i need to run using Process.Start(<script name>) and have all the output and error messages written to a log file, and i need to do this async (using backgroundworker) so the UI will not freeze.

    for some reason when I run the main script from DOS everything is OK but when using C# code it doesn't work and doesn't give me any logs.

    I should state that i'm running on clustered servers if it makes any difference. The code I use:


    BackgroundWorker worker = new BackgroundWorker();
      void RunProcessAsync()
       ProcessStartInfo psi = new ProcessStartInfo(c_MainScriptName)
        psi.RedirectStandardError = true,
        psi.RedirectStandardInput = true,
        psi.RedirectStandardOutput = true,
        psi.UseShellExecute = false,
        psi.CreateNoWindow = true
       Process p = Process.Start(psi);
       if (p != null)
        p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
        p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
        worker.RunWorkerCompleted += ProcessedFinished;
        worker.DoWork += WaitForProcess;
      void ProcessedFinished(object sender, RunWorkerCompletedEventArgs e)
       Process p = e.Result;
       worker.RunWorkerCompleted -= ProcessedFinished;
       worker.DoWork -= WaitForProcess;
      void WaitForProcess(object sender, DoWorkEventArgs e)
       Process p = e.Argument;
       e.Result = p;


    (sorry it's so long)

    As i said the script (that has in it a call to psexec) fails using these code but works using DOS, also it doesn't write all the log files but only a bit, usually states exit code 1.

    anyone has any idea what to do so this will work?




    sainity is overrated
    Tuesday, August 24, 2010 10:38 AM