System.Diagnostics.Process not working !! please help

Discussion in 'ASP .Net Web Services' started by Nurit N, Jan 5, 2006.

  1. Nurit N

    Nurit N Guest

    I wrote that post also on other newsgroup but didn't get any answers.

    So, I'm trying it here. Maybe it's the right place for it...

    I have created a very simple batch file (echo hello world) and was trying to
    retrieve the standard output but every time I run the code it returns
    ExitCode as 1.

    The batch file runs just fine from command line.

    There is no Win32Exception (no ERROR_FILE_NOT_FOUND and no
    ERROR_ACCESS_DENIED)

    Also strOutput and strError returns empty.

    What ExitCode1 means?

    Am I missing on something?

    Here is the code:

    try
    {
    System.Diagnostics.Process MFGProc = new System.Diagnostics.Process();
    MFGProc.StartInfo.FileName = strMfgWorkDir + strMfgBatFile;
    MFGProc.StartInfo.WorkingDirectory = strMfgWorkDir;
    MFGProc.StartInfo.UseShellExecute = false;
    MFGProc.StartInfo.RedirectStandardError = true;
    MFGProc.StartInfo.RedirectStandardOutput = true;
    MFGProc.Start();

    string strOutput = MFGProc.StandardOutput.ReadToEnd();
    string strError = MFGProc.StandardError.ReadToEnd();
    MFGProc.WaitForExit();

    if (MFGProc.ExitCode == 0)
    {
    Ok = true;
    }
    else
    {
    strErrorMsg = " Running failed. Description: " + strError;
    }
    }
    catch (Win32Exception e)
    {
    strErrorMsg = "W32 Error:" + e.NativeErrorCode.ToString() + "." +
    e.Message ;
    }

    catch (Exception err)
    {
    // Process other errors here
    strErrorMsg = ("RunMFGCimSession Other error. ErrorMessage: " +
    err.Message );
    }

    Thanks

    Nurit
     
    Nurit N, Jan 5, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simple Simon
    Replies:
    0
    Views:
    380
    Simple Simon
    Dec 15, 2003
  2. Ron Fidel
    Replies:
    4
    Views:
    4,165
    Ronen Fidel
    Jan 15, 2004
  3. Michael Johnson Sr.

    System.Diagnostics, Process and Security

    Michael Johnson Sr., Feb 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,874
    Michael Johnson Sr.
    Feb 13, 2004
  4. Heiko Besemann
    Replies:
    1
    Views:
    2,923
    Harsh Thakur
    Feb 19, 2004
  5. Steve Bishop

    System.Diagnostics.Process Question

    Steve Bishop, Feb 27, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,418
    Eric Lawrence [MSFT]
    Mar 1, 2004
Loading...

Share This Page