473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

streaming the output of a batch file to a text box?

ed
Hi all,
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

Aug 24 '06 #1
4 13351
"ed" <ed***********@gmail.comschrieb:
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/>
Aug 24 '06 #2
ed
Herfried K. Wagner [MVP] wrote:
"ed" <ed***********@gmail.comschrieb:
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/>
Hi Herfried,
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
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

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

Aug 24 '06 #3
ed wrote:
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
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
Batch files are run by the command processor (cmd.exe). In order to do
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

Aug 24 '06 #4
ed

Chris Dunaway wrote:
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
Many thanks for your help chris... german + no experiance kinda
confised me...

I will do as you say and read the manuals. Thanks a lot for the
example code!

Regards,
-Ed

Aug 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: vbnetrookie | last post by:
Hi all, This is my first batch file and I want to query a database and output it in a textfile. Up to now that works, the only problem is the formatting in the text file. It's all screewed...
2
by: carolineb2005 | last post by:
I have compiled this simple program which accept arguments on line using System; class HelloWorld { public static void Main(string args) { Console.WriteLine("Hello ", args); } }
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
1
by: steve | last post by:
Hi all, Here's some work in progress that should allow you to run a batch file as a custom action in a VS deployment project. Yup I know you can use js or wsh, but the target may not have...
0
by: Elroyskimms | last post by:
I need to execute a batch file via ASP.Net. In my VB.Net code, I'm using System.Diagnostics.Process to call the batch file and its appropriate command line arguments. I'm using...
7
by: Nananana | last post by:
Hi. I have 2 DB2 statements: connect select How can I create a batch file and redirect the output to a file? I would like something like this:
0
by: Vijay Kumar | last post by:
Hi, I have a batch file(test.bat) i wrote a command to rename a text file in this batch file. Both batch file and text files are in Network Shared Drive. I am trying to run that batch file from...
3
by: n o s p a m p l e a s e | last post by:
Suppose I have a batch file called mybatch.bat and I want to run it from a python script. How can I call this batch file in python script? Thanx/NSP
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.