|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
streaming the output of a batch file to a text box?I'm very new to vb (2nd day) and I need to create a small app that will replace my old batch file with a flashy gui. I had some experience with access 2.0 which helps ;) What I would like is to get the output of the batch file to display on the gui as the batch file is running. if some of you understand unix... I want this: tail -f /var/log/messages If it's not possible to stream it, I'd like to find a way to output the result at the end of the batch file execution. Last but not least, how do I hide the batch window when it executes so that the user only sees the gui? Thank you all, -Ed "ed" <edoardo.co***@gmail.com> schrieb: <URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole.zip>> I'm very new to vb (2nd day) and I need to create a small app that will > replace my old batch file with a flashy gui. I had some experience > with access 2.0 which helps ;) > > What I would like is to get the output of the batch file to display on > the gui as the batch file is running. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Herfried K. Wagner [MVP] wrote:
Show quoteHide quote > "ed" <edoardo.co***@gmail.com> schrieb: Hi Herfried,> > I'm very new to vb (2nd day) and I need to create a small app that will > > replace my old batch file with a flashy gui. I had some experience > > with access 2.0 which helps ;) > > > > What I would like is to get the output of the batch file to display on > > the gui as the batch file is running. > > <URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole.zip> > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Like I said, I'm pretty new to VB but I don't think this does what I'm looking for. >From what I can tell it opens a text file with notepad in the bin What I am looking for is a way to stream the output of a batch filedirectory. into the gui so say my batch had 2 lines echo Hello echo World It would do this: [batch] "echo Hello" -stream-> [gui] "Hello" [batch] "echo World" -stream-> [gui] "World" then the batch closes and the rest of the commands are launched... Anyone else got an idea? thanks ed wrote:
> Like I said, I'm pretty new to VB but I don't think this does what I'm Batch files are run by the command processor (cmd.exe). In order to do> looking for. > >From what I can tell it opens a text file with notepad in the bin > directory. > > What I am looking for is a way to stream the output of a batch file > into the gui so say my batch had 2 lines what you want, you need use Process.Start to run cmd.exe and pass it the appropriate parameters to execute your batch file. The Process class has a property called RedirectStandardOutput. You would set that to True and then in your program, you would have to open the standard output stream to get the output from the batch file. The RedirectConsole example that Herfried posted shows how to do that. Although his comments are in german, the code is fairly straight forward. Here is another example that executes a batch file and captures its output: Using m_Process As New Process() With m_Process.StartInfo .FileName = "cmd.exe" .UseShellExecute = False .CreateNoWindow = True .RedirectStandardOutput = True .Arguments = "/C c:\test\test.bat" End With m_Process.Start() m_Process.WaitForExit(5000) Dim output As String = m_Process.StandardOutput.ReadLine() While output <> Nothing TextBox1.Text &= output & vbCrLf output = m_Process.StandardOutput.ReadLine() End While End Using If the batch file has errors, they may be displayed on the StandardError stream instead of the StandardOutput stream. Be sure to read the docs on the RedirectStandardError property because there is the possibility of a deadlock if you try to read both the standard output and error streams at the same time. The docs tell how to avoid that. Chris Chris Dunaway wrote:
Show quoteHide quote > Using m_Process As New Process() Many thanks for your help chris... german + no experiance kinda> With m_Process.StartInfo > .FileName = "cmd.exe" > .UseShellExecute = False > .CreateNoWindow = True > .RedirectStandardOutput = True > .Arguments = "/C c:\test\test.bat" > End With > > m_Process.Start() > m_Process.WaitForExit(5000) > > Dim output As String = m_Process.StandardOutput.ReadLine() > While output <> Nothing > TextBox1.Text &= output & vbCrLf > output = m_Process.StandardOutput.ReadLine() > End While > End Using > > If the batch file has errors, they may be displayed on the > StandardError stream instead of the StandardOutput stream. Be sure to > read the docs on the RedirectStandardError property because there is > the possibility of a deadlock if you try to read both the standard > output and error streams at the same time. The docs tell how to avoid > that. > > Chris confised me... I will do as you say and read the manuals. Thanks a lot for the example code! Regards, -Ed
Where is the "default" property of the Command Button Object in VB.net
Get text file content into SQL table translating more stuff from C Search DataRow Array Array of a Class - Weird Output Wireless Electronics/Cell Phones/GPS/Text Messaging not able to run the Process Problem re-enabling menu item need advices on Global Error Handling in VB.Net Checkbox list questions |
|||||||||||||||||||||||