
04-02-2012, 10:30 AM
|
|
Newcomer
|
|
Join Date: Oct 2011
Posts: 8
|
|
Console output and dos for command
|
Hello,
I'm writing a vb6 console application and like to use the dos 'for command' to parse the output of my created executable.
SCENARIO:
I have following VB6 code:
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function GetStdHandle& Lib "kernel32" (ByVal nStdHandle&)
Declare Function WriteConsole& Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput&, lpBuffer As Any, ByVal nNumberOfCharsToWrite&, lpNumberOfCharsWritten&, lpReserved As Any)
Sub Main()
Dim hOut&, lpWritten&, sText$
hOut = GetStdHandle(-11)
sText = "Hello"
WriteConsole hOut, ByVal sText, Len(sText), lpWritten, ByVal 0&
'WriteFile hOut, ByVal sText, Len(sText), lpWritten, 0
CloseHandle hOut
End Sub
The created exe is Project1.exe, after the build I ran:
LINK.EXE" /EDIT /SUBSYSTEM:CONSOLE Project1.exe
Then I try to use the dos for command on the prompt in cmd.exe:
for /f %a in ('Project1.exe') do (echo %a)
PROBLEM:
If I use WriteFile (commented) everything is working fine, but if I use WriteConsole it doesn't work
However it is still possible to use Project1.exe >nul on the commandline
But I'm not able to pipe it to GNUWin32's grep: Project1 | grep Hello
So what am I doing wrong?
|
|