Re: CMD



peek^ <sniffpeek@xxxxxxxxxxx> wrote:
Hi. I have a DOS, well windows console, program. I wonder if there is any
way to call it, but instead of a CMD window, I want it to appear in my own
window. Like have the prompt displayed on TEdit control, or something.
Anyway to do that?

Possibly. You'll need to create a pipe, to read the standard output from the
created process. I picked the essence of this routine from the commented link
within:

Private Function ExecAndCapture(ByVal CmdLine As String, Optional ByVal
StartFolder As String = vbNullString) As String
' http://www.vb-helper.com/howto_capture_console_stdout.html
Dim hPipeRead As Long
Dim hPipeWrite As Long
Dim sa As SECURITY_ATTRIBUTES
Dim si As STARTUPINFO
Dim pi As PROCESS_INFORMATION
Dim Buffer() As Byte
Dim StdOut As New CStringBuilder
Dim lBytesRead As Long
Dim ExitCode As Long
Const BUFSIZE As Long = 1024 * 10

With sa
.nLength = Len(sa)
.bInheritHandle = 1 ' get inheritable pipe handles
End With 'SA

If CreatePipe(hPipeRead, hPipeWrite, sa, 0) = 0 Then
Exit Function
End If

With si
.cb = Len(si)
.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
.wShowWindow = SW_HIDE
.hStdOutput = hPipeWrite
.hStdError = hPipeWrite
End With 'SI

If CreateProcess(vbNullString, CmdLine, ByVal 0&, ByVal 0&, 1, 0&, ByVal 0&,
StartFolder, si, pi) Then
Call CloseHandle(hPipeWrite)
Call CloseHandle(pi.hThread)

ReDim Buffer(0 To BUFSIZE - 1) As Byte
Do
DoEvents
If ReadFile(hPipeRead, Buffer(0), UBound(Buffer) + 1, lBytesRead, ByVal
0&) = 0 Then
Exit Do
End If
Debug.Print Replace$(Left$(StrConv(Buffer, vbUnicode), lBytesRead),
vbCr & vbCrLf, vbCrLf);
StdOut.Append Replace$(Left$(StrConv(Buffer, vbUnicode), lBytesRead),
vbCr & vbCrLf, vbCrLf)
Loop
Call CloseHandle(pi.hProcess)
End If

' To make sure...
Call CloseHandle(hPipeRead)
Call CloseHandle(hPipeWrite)

' Return results.
ExecAndCapture = StdOut.ToString
End Function

Probably not drop-in ready, but should give you an idea or three.
--
..NET: It's About Trust!
http://vfred.mvps.org


.



Relevant Pages

  • Re: Event Log Query
    ... Dim gb_echo, gb_popup ... Sub s_initialize ... On Error Goto 0 ...
    (microsoft.public.scripting.vbscript)
  • Re: Eval code and AppDomains
    ... Crossing app domains and generating these assemblies ... > I needed a way to Eval this string and return a Boolean result. ... > Dim objEval As New EvalProvider ... > sb.Append("Imports System.Data" & vbCrLf) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using ADODB.Recordset
    ... If you remove al the vbcrlf statements and replace them with spaces. ... Dim DealID As Long, sSql As String ... Const adOpenForwardOnly As Long = 0 ... Basically, I am grabbing a one row recordset, and i would like to ...
    (microsoft.public.excel.programming)
  • Event Log Query
    ... I've created a script that does the following: ... Dim objLogFile ... objLog.Write vbCrlf ... Dim intFreeSpace ...
    (microsoft.public.scripting.vbscript)
  • Re: Cancel button command
    ... Dim items() As String ... Dim itemslist As String ... vbCrLf) ... Total = subamount - primesavings Dim strSelectedItems As String = txtItems.Text Dim strReportHeader As String ...
    (microsoft.public.dotnet.languages.vb)