Wrox Programmer Forums
|
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2006, 01:00 AM
Authorized User
 
Join Date: Mar 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Capturing the output of a DOS mode program

Hi Rod

I need to run a DOS program from within my application and capture the output. Basically the DOS program is a command line compiler. I need to grab the output and display it in my VB.NET 2005 program. I have searched around for a solution and looked in your excellent book and web site. I can find stuff for VB6 but nothing for VB.NET. Seems that it ought to be simple but looks like it isn't. Any pointers would be much appreciated

Thanks


Jon Masterson
__________________
Jon Masterson
 
Old April 29th, 2006, 09:15 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi Jon,

Like everything in .NET, it's not too hard once you know which classes and namespaces to use. See this example:

    http://www.vb-helper.com/howto_net_run_dos.html

Here's the heart of it:

    ' Set start information.
    Dim start_info As New ProcessStartInfo(txtProgram.Text)
    start_info.UseShellExecute = False
    start_info.CreateNoWindow = True
    start_info.RedirectStandardOutput = True
    start_info.RedirectStandardError = True

    ' Make the process and set its start information.
    Dim proc As New Process()
    proc.StartInfo = start_info

    ' Start the process.
    proc.Start()

    ' Attach to stdout and stderr.
    Dim std_out As StreamReader = proc.StandardOutput()
    Dim std_err As StreamReader = proc.StandardError()

    ' Display the results.
    txtStdout.Text = std_out.ReadToEnd()
    txtStderr.Text = std_err.ReadToEnd()

    ' Clean up.
    std_out.Close()
    std_err.Close()
    proc.Close()

Best wishes,

Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm
 
Old April 29th, 2006, 10:33 AM
Authorized User
 
Join Date: Mar 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rod

Many thanks - that did the trick once I figured out how to use the arguments property :)

I searched your site first and only came up with the VB6 version - I should have looked harder

Jon Masterson





Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing Output Parameter Value GailCG SQL Server 2005 1 November 19th, 2008 08:52 AM
Printing Problem (dos Mode) Arunachalam Beginning VB 6 0 October 5th, 2006 02:17 AM
C++ Network Printing Problem from DOS mode Khusnitdin C++ Programming 1 January 11th, 2005 09:24 AM
Pass arguments to dos program gregquinn Beginning VB 6 1 December 10th, 2003 05:38 AM
Capturing cmd output Chris Beach C# 0 October 3rd, 2003 04:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.