Getting results from a Process in VB.NET


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Getting results from a Process in VB.NET

  1. #1
    Join Date
    Apr 2005
    Location
    Tempe, Arizona
    Posts
    4

    Question Getting results from a Process in VB.NET

    I work for ASU and we have a centralized web authentication method that requires me to verify a authenticator string through a executable on the web server. With the following function I am able to start the process and get the Exit Code, but the process also returns a string, but I cannot figure out how to get the string from the process.

    Public Function authenticateUser() As String
    Dim strCmdLine As String
    strCmdLine = "-c:" & Page.Request.QueryString("authenticator") & " -h:WEBAUTH.ASU.EDU -b:"
    strCmdLine += Page.Request.ServerVariables("REMOTE_ADDR") & " -n"

    Dim authenProcess As System.Diagnostics.Process
    Try
    authenProcess = New System.Diagnostics.Process
    authenProcess.StartInfo.FileName = "c:\windows\verify.exe"
    authenProcess.StartInfo.Arguments = strCmdLine
    authenProcess.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Hidden

    'Wait until the process passes back an exit code
    authenProcess.WaitForExit()
    authenticateUser = authenProcess.ExitCode

    'Free resources associated with this process
    authenProcess.Close()
    Catch ex As Exception
    authenticateUser = "ERROR: No Results from Process"
    End Try

    Return authenticateUser
    End Function

    Any assistance on this would be greatly appreciated.

    Thanks
    Eric

  2. #2
    Join Date
    Nov 2003
    Posts
    154
    Try this article: How to Pass Parameters to Threads in Windows Forms Applications and Get Results (http://www.devx.com/dotnet/Article/11358)
    A. Russell Jones,
    Executive Editor,
    Internet.com

  3. #3
    Join Date
    Apr 2005
    Location
    Tempe, Arizona
    Posts
    4
    Hello Russell,
    I am not using a Windows Form for this project but a web application, will the process work the same for either?

    Eric

  4. #4
    Join Date
    Nov 2003
    Posts
    154
    Yes, the process works the same way, but with Web applications, you can easily cause problems by running single-threaded applications on the server (threading issues), or by running separate threads that may not complete by the time the Web request completes (timing issues), or when the process that you launch takes a long (relatively speaking) time (resource issues). Consider wrapping the authentication process into a separate dll that you run as a COM+ server (see System.Enterprise.Services) component.
    A. Russell Jones,
    Executive Editor,
    Internet.com

  5. #5
    Join Date
    Apr 2005
    Location
    Tempe, Arizona
    Posts
    4
    Thanks for the quick response. I getting in over my head, as I'm a new to ASP.NET, but I should be able to work it out.

    Eric

  6. #6
    Join Date
    Sep 2004
    Posts
    9

    Das ist eine gute frage.

    I was thinking, "how do you read standard output in C#"?
    Well, it might be something like this:
    void ReadStdOut()
    {
    string str;
    while ((str = process.StandardOutput.ReadLine()) != null)
    {
    // do something with str
    }
    }

    You have to set:

    Process process = new Process();
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;

    I got this from http://www.codeproject.com/csharp/LaunchProcess.asp
    If this works for you, please let me know, since I am sure I will have to use in the near future. Note: I haven't tried it.

    Tonci Korsano

    "What you think doesn't matter. What matters is evidence!"

  7. #7
    Join Date
    Apr 2005
    Location
    Tempe, Arizona
    Posts
    4

    Thumbs up It's working, using System.Diagnostics.Process

    In testing and talking with several different persons here at the university, we came up with this solution:

    authInfo.RedirectStandardOutput = True
    authInfo.UseShellExecute = False
    authInfo.FileName = FilePath
    authInfo.Arguments = CommandLineArguments

    Dim authProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start(authInfo)
    Dim strAuthResults As String = authProcess.StandardOutput.ReadToEnd()
    authProcess.WaitForExit()
    authProcess.Close()

    Thanks to all who responded.

    Eric

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center