-
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
-
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

-
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
-
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

-
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
-
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!"
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks