Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Console output and dos for command


Reply
 
Thread Tools Display Modes
  #1  
Old 04-02-2012, 10:30 AM
vbmani vbmani is offline
Newcomer
 
Join Date: Oct 2011
Posts: 8
Default 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?
Reply With Quote
Reply

Tags
console output dos for


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->