AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed Rizwan Muhammad Rizvi
Expertise
I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.

Experience
Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > Write error to cmd prompt dialog

Topic: VB.NET



Expert: Syed Rizwan Muhammad Rizvi
Date: 6/19/2008
Subject: Write error to cmd prompt dialog

Question
Basically, I'm starting my own cmd prompt through my program. I've modified the input/output, and useshellexecute = false.
When I try to have the line write, it writes, but can't find the process (taskkill.exe /f /im taskname.exe) and errors. My original thought was that it wouldn't be a problem, and I could use a streamreader to import the error message into a textbox control - however, that obviously doesn't work, and through the debugging I've done, I've come to the conclusion that .net treats it as a failed write (it keeps trying to execute the SI.WriteLine("taskkill.exe /f /im wuauclt.exe /t") over and over and over). I've narrowed it down to a NullReferenceException, but can't figure out how to manipulate the control to ignore the error and return the result to the textbox control.
Snippets:
   Public startcmd As New Process
   Public cmdinfo As New System.Diagnostics.ProcessStartInfo

       cmdinfo.FileName = "cmd"
       cmdinfo.RedirectStandardInput = True
       cmdinfo.RedirectStandardOutput = True
       cmdinfo.UseShellExecute = False
       cmdinfo.CreateNoWindow = True (doesn't do anything)
       cmdinfo.WindowStyle = ProcessWindowStyle.Hidden (doesn't do anything)
       startcmd.StartInfo = cmdinfo
       startcmd.Start()

       Static seconds As Integer = 15
       If seconds = 0 Then
           Dim SO As System.IO.StreamReader = startcmd.StandardOutput
           Dim SI As System.IO.StreamWriter = startcmd.StandardInput
           Dim error1 As NullReferenceException
           SI.WriteLine("taskkill.exe /f /im wuauclt.exe /t")
           txtLoadedLog.Text = txtLoadedLog.Text & vbCrLf & SO.ReadToEnd
           SI.Close()
           SO.Close()
           seconds = 15
       End If
       seconds -= 1

Sorry it's so much code... I've been at it for several hours now and can't (for the life of me) figure this out.

Thanks much!

Answer
Hi,

I have checked your code it seems to be working fine. I think you need a bit more info on WaitForExit() Which you can find from here.
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redi...

Moreover there is a logical flaw which you will see when you will try to implement wait for exit. because you are using cmd command and not directly using taskkill.exe once the this command terminates it won't close cmd unless you send "exit" command to cmd which will close the application and unblock the call to the process.

Regards,
Riz

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.