Results 1 to 4 of 4

Thread: writing commands to Command Prompt Using VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    3

    writing commands to Command Prompt Using VB

    Hi all,

    I am using Visual Studio 2010, VB to compile my program. My program include having to open a command prompt and writing a command to it. and display the output/errors in a textbox. But i can't seems to make it display it in a textbox and it opens ALOT of command prompts windows. Any help would be greatly appreaciated! Below is the my code:

    Code:
     
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
            Try
                Dim P As New Process
                With P
                    .StartInfo.FileName = "cmd.exe"
                    .StartInfo.RedirectStandardOutput = True
                    .StartInfo.UseShellExecute = False
                    .Start()
                    SendKeys.Send("julian.exe. -input mic -C julian.jconf" & "{enter}")
                    Output.Text &= .StandardOutput.ReadToEnd()
                    .WaitForExit()
                End With
            Catch ex As Exception
            End Try
        End Sub

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: writing commands to Command Prompt Using VB

    Welcome to VBForums.

    Why not execute the julian.exe process directly? Is there a reason why you must first open up the command prompt, and then launch julian.exe from it?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    3

    Re: writing commands to Command Prompt Using VB

    Hi,

    I tried running julian.exe directly but it gave me this error
    "A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll"

    Maybe it's because julian.exe is a linux based program.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    3

    Re: writing commands to Command Prompt Using VB

    When i took out this 2 lines :
    vb Code:
    1. .StartInfo.RedirectStandardOutput = True
    2.                 .StartInfo.RedirectStandardError = True

    It can open the cmd window and run smoothly.

    But without the above 2 lines, how do i display the output of the cmd prompt in a textbox?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width