Travis Hydzik
asked on
creating a VB6 console application capable of piping the output
I have successfully created a console application that outputs text to the console, see the code. However, I can't pipe this to a text file. ie project1.exe > c:\a.txt just creates and empty file.
comments on how to achieve this would be appreciated.
Note; I am also linking the application with link.exe
comments on how to achieve this would be appreciated.
Note; I am also linking the application with link.exe
Option Explicit
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private Declare Function WriteConsole _
Lib "kernel32" Alias "WriteConsoleA" ( _
ByVal hConsoleOutput As Long, _
ByVal lpBuffer As Any, _
ByVal nNumberOfCharsToWrite As Long, _
ByVal lpNumberOfCharsWritten As Long, _
ByVal lpReserved As Any) _
As Long
Private Const STD_OUTPUT_HANDLE = -11&
Private Sub Main()
Dim hConsoleOut As Long
Dim MsgOut As String
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
MsgOut = "this is a test string"
WriteConsole hConsoleOut, MsgOut, Len(MsgOut), vbNull, ByVal 0&
FreeConsole
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try the approach here also:
https://www.experts-exchange.com/questions/22090333/Console-printing.html
https://www.experts-exchange.com/questions/22090333/Console-printing.html
ASKER
egl1044,
thanks for that, the only problem with the code is that
AttachConsole(ATTACH_PAREN T_PROCESS) is false and it skips over this section
thanks for that, the only problem with the code is that
AttachConsole(ATTACH_PAREN
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
egl1044,
ahh, thanks, exactly the answer I was wanting.
I commented it out and it worked well, so was wondering why it was included
ahh, thanks, exactly the answer I was wanting.
I commented it out and it worked well, so was wondering why it was included
ASKER
thank you.
http://msdn.microsoft.com/en-us/library/ms687401(VS.85).aspx
The Remarks section has the follow information:
Both WriteConsole and WriteFile can be used for console I/O. While WriteConsole supports writing Unicode characters to a console screen buffer, WriteFile does not. However, WriteConsole fails if it is used with a standard handle that is redirected to a file.