CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2000
    Location
    Maryland
    Posts
    181

    How do I output a simple string to console (DOS)

    I can use the code below to write a simple string such as “I love my mother to console. The abbreviated code below can output the contents (files and subdirectories of “F:\Program Files\Microsoft Visual Studio\VB98>” in that directory in that very directory. But I just want to output a simple string.

    Public Sub ExecCmd(CmdLine As String)

    'Dim ReturnValue As Integer

    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO

    Dim retval As Long

    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)

    ' Start the shelled application:
    retval& = CreateProcessA(vbNullString, CmdLine$, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

    '//Build Command string
    ' exit
    CmdLine = "Exit"
    'ExecCmd (CmdLine)

    ' mmk 05.14.2004 added to enable exiting
    retval& = CreateProcessA(vbNullString, CmdLine$, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

    ' Wait for the shelled application to finish:
    'retval& = WaitForSingleObject(proc.hProcess, INFINITE)
    Call GetExitCodeProcess(proc.hProcess, retval&)
    Call CloseHandle(proc.hThread)
    Call CloseHandle(proc.hProcess)
    'ExecCmd = retval&

    End Sub

    'MMKLike
    Private Sub Form_Load()

    ' init some values for the query strings (note: it _always_ needs a query for YearBuilt,
    ' I just set it to be one less than the lowest number in the db. This is a cheap hack.
    ' It does get requeried on the fly, this just sort of seeds the preliminary results. The
    ' reason there needs to be a yearbuilt query is that everything else gets anded on the
    ' end, and without it the logic won't make sense to the sql query dude.)

    On Error GoTo TrapIt

    Dim retval As Long

    ' mmk remed out
    MsgBox "Process Finished, Exit Code " & retval

    Dim AppToRun As String
    Dim ParamForApp As String
    Dim CmdLine As String
    Select Case getVersion
    Case "Windows 95", "Windows 98", "Windows Mellinnium"
    AppToRun = "Command.exe"
    Case "Windows NT 3.51", "Windows NT 4.0", "Windows 2000", "Windows XP"
    AppToRun = "Cmd.exe"
    Case "Failed"
    MsgBox "Unable to determine Os type"
    Exit Sub
    End Select

    '//set Command Line Parameters
    '//The "/C" Tells Windows to Run The Command then Terminate
    '//The Command Line (CMD.exe)
    'ParamForApp = " /C MD New_Folder" '//Make new Directory Called 'New_Folder'
    'use /C to launch command without see windwow

    'use /K to see output
    ParamForApp = " /K dir"
    'ParamForApp = " /C MD New_Folder" '//Make new Directory Called 'New_Folder'

    '//Build Command string
    ' mmk must restore
    CmdLine = AppToRun '& ParamForApp

    'retval =
    'ExecCmd ("notepad.exe")
    ExecCmd (CmdLine)

    'mmk 05.13.2004 added
    'EndApplication 1

    Exit_This:

    Exit Sub

    TrapIt:

    errorMessage = "Error Number = " & Err.Number & " - " & Err.Description & "."
    'LogErrorMessage "Form_Load()", errorMessage, 2

    Resume Exit_This

    End Sub

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

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

Featured