本人现在要用调用一外部DOS程序.
希望在VB窗体或TEXTBOX 中及时显示外部程序运行信息.
在DOS窗口中不希望显示信息.
如果做?
谢谢!!!!

解决方案 »

  1.   

    谢谢.
    用什么函数.API不重要,但是怎么实现呢?
    我不想用重定向在文件中
    请大侠帮助!
      

  2.   

    SetStdHandle重定向dos窗口的标准输入输出,可使用管道,ReadFile/WriteFile读出写入。
      

  3.   

    SHELL达不到要求,它会跳出提示符窗口.而不会在编辑框中输入并显示.
      

  4.   

    用VB实现控制台,text1输入命令
    text2设成多行显示,输出结果
    注意dos内部命令的执行要加上cmd /c
    cmd/c dirOption ExplicitPrivate Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long
    Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO)
    Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
    Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Type SECURITY_ATTRIBUTES
      nLength As Long
      lpSecurityDescriptor As Long
      bInheritHandle As Long
    End TypePrivate Type PROCESS_INFORMATION
      hProcess As Long
      hThread As Long
      dwProcessId As Long
      dwThreadId As Long
    End TypePrivate Type STARTUPINFO
      cb As Long
      lpReserved As Long
      lpDesktop As Long
      lpTitle As Long
      dwX As Long
      dwY As Long
      dwXSize As Long
      dwYSize As Long
      dwXCountChars As Long
      dwYCountChars As Long
      dwFillAttribute As Long
      dwFlags As Long
      wShowWindow As Integer
      cbReserved2 As Integer
      lpReserved2 As Byte
      hStdInput As Long
      hStdOutput As Long
      hStdError As Long
    End TypePrivate Type OVERLAPPED
        ternal As Long
        ternalHigh As Long
        offset As Long
        OffsetHigh As Long
        hEvent As Long
    End TypePrivate Const STARTF_USESHOWWINDOW = &H1
    Private Const STARTF_USESTDHANDLES = &H100
    Private Const SW_HIDE = 0
    Private Const EM_SETSEL = &HB1
    Private Const EM_REPLACESEL = &HC2Private Sub Command1_Click()
      Command1.Enabled = False
      Redirect Text1.Text, Text2
      Command1.Enabled = True
    End Sub
    Private Sub Form_Load()
        Text1.Text = "ping"
    End Sub
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
      If Command1.Enabled = False Then Cancel = True
    End SubSub Redirect(cmdLine As String, objTarget As Object)
      Dim i%, t$
      Dim pa As SECURITY_ATTRIBUTES
      Dim pra As SECURITY_ATTRIBUTES
      Dim tra As SECURITY_ATTRIBUTES
      Dim pi As PROCESS_INFORMATION
      Dim sui As STARTUPINFO
      Dim hRead As Long
      Dim hWrite As Long
      Dim bRead As Long
      Dim lpBuffer(1024) As Byte
      pa.nLength = Len(pa)
      pa.lpSecurityDescriptor = 0
      pa.bInheritHandle = True
      
      pra.nLength = Len(pra)
      tra.nLength = Len(tra)  If CreatePipe(hRead, hWrite, pa, 0) <> 0 Then
        sui.cb = Len(sui)
        GetStartupInfo sui
        sui.hStdOutput = hWrite
        sui.hStdError = hWrite
        sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
        sui.wShowWindow = SW_HIDE
        If CreateProcess(vbNullString, cmdLine, pra, tra, True, 0, Null, vbNullString, sui, pi) <> 0 Then
          SetWindowText objTarget.hwnd, ""
          Do
            Erase lpBuffer()
            If ReadFile(hRead, lpBuffer(0), 1023, bRead, ByVal 0&) Then
              SendMessage objTarget.hwnd, EM_SETSEL, -1, 0
              SendMessage objTarget.hwnd, EM_REPLACESEL, False, lpBuffer(0)
              DoEvents
            Else
              CloseHandle pi.hThread
              CloseHandle pi.hProcess
              Exit Do
            End If
            CloseHandle hWrite
          Loop
          CloseHandle hRead
        End If
      End If
    End Sub
      

  5.   

    感谢: ch21st(风尘鸟.shannon) 
          4103796(潇湘予)
      

  6.   

    实现下面问题:
    1)  cd C:\HARP\HARP_Projects\Spar3000_1stOrder\Wamit2)  call C:\HARP\Code\Wamit\wampostNewmanrao.exe3)   C:\HARP\Code\Wamit\wampostNewmanrao.exe
      

  7.   

    会出现以下错误信息:
    C:\Program Files\Micorsoft\Visul Studio\VB98\vb6.exe
    %SystemRoot%\SYSTEM32\CONFIG.NT.The system file is not suitable for running MS-DOS and Microsoft Window applications.