-
stdout -- Why is it so hard?
So I am trying to pass a value back to stdout after executing a VB application
with command switches from command line. Although it appears to get a valid
handle, nothing is returned to the shell session.
Here is what I am doing.....
Option Explicit
Public Const STD_OUTPUT_HANDLE = -11&
Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle" _
(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
Public Declare Function WriteFile Lib "kernel32" _
(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
As Long, _
lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
As Long
Public Function stdout()
Dim sWriteBuffer As String
Dim lBytesWritten As Long
Dim hStdOut As Long
'Send something to stdout
sWriteBuffer = "This really sucks!" & vbCrLf
hStdOut = w32_stdout()
WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
End Function
Any suggestions on how to return a value to the command line via stdout or
another method? I hate to say it but in C this is cake. Why does it have
to be so hard in VB.
Thanks!
-
Re: stdout -- Why is it so hard?
http://www.win2000mag.com/Articles/I...cleID=565&pg=1
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Monte Hansen
http://KillerVB.com
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
"Joe Shields" <joe.shields@wellsfargo.com> wrote:
>
>So I am trying to pass a value back to stdout after executing a VB application
>with command switches from command line. Although it appears to get a valid
>handle, nothing is returned to the shell session.
>
>Here is what I am doing.....
>
>Option Explicit
>
>Public Const STD_OUTPUT_HANDLE = -11&
>
>Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle" _
>(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
>
>Public Declare Function WriteFile Lib "kernel32" _
>(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
>As Long, _
>lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
>As Long
>
>Public Function stdout()
>
>Dim sWriteBuffer As String
>Dim lBytesWritten As Long
>Dim hStdOut As Long
>
>
>'Send something to stdout
>sWriteBuffer = "This really sucks!" & vbCrLf
>hStdOut = w32_stdout()
>WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
>
>
>
>End Function
>
>Any suggestions on how to return a value to the command line via stdout
or
>another method? I hate to say it but in C this is cake. Why does it have
>to be so hard in VB.
>
>Thanks!
-
Re: stdout -- Why is it so hard?
http://www.win2000mag.com/Articles/I...cleID=565&pg=1
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Monte Hansen
http://KillerVB.com
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
"Joe Shields" <joe.shields@wellsfargo.com> wrote:
>
>So I am trying to pass a value back to stdout after executing a VB application
>with command switches from command line. Although it appears to get a valid
>handle, nothing is returned to the shell session.
>
>Here is what I am doing.....
>
>Option Explicit
>
>Public Const STD_OUTPUT_HANDLE = -11&
>
>Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle" _
>(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
>
>Public Declare Function WriteFile Lib "kernel32" _
>(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
>As Long, _
>lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
>As Long
>
>Public Function stdout()
>
>Dim sWriteBuffer As String
>Dim lBytesWritten As Long
>Dim hStdOut As Long
>
>
>'Send something to stdout
>sWriteBuffer = "This really sucks!" & vbCrLf
>hStdOut = w32_stdout()
>WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
>
>
>
>End Function
>
>Any suggestions on how to return a value to the command line via stdout
or
>another method? I hate to say it but in C this is cake. Why does it have
>to be so hard in VB.
>
>Thanks!
-
Re: stdout -- Why is it so hard?
This article is essentially a regurgitation of Q239588. The problem is that
it doesn't actually write back to the shell. If you take the code provided
in the article... it doesn't return anything to the shell. If it is calling
a new command shell then it can do it no problem. It looks like the problem
is obtaining the valid handle. Still not sure what to do.
Thanks!
Joe
"Monte Hansen" <monte@nospam.com> wrote:
>
>http://www.win2000mag.com/Articles/I...cleID=565&pg=1
>
>+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
>Monte Hansen
>http://KillerVB.com
>+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
>
>
>
>"Joe Shields" <joe.shields@wellsfargo.com> wrote:
>>
>>So I am trying to pass a value back to stdout after executing a VB application
>>with command switches from command line. Although it appears to get a valid
>>handle, nothing is returned to the shell session.
>>
>>Here is what I am doing.....
>>
>>Option Explicit
>>
>>Public Const STD_OUTPUT_HANDLE = -11&
>>
>>Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle"
_
>>(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
>>
>>Public Declare Function WriteFile Lib "kernel32" _
>>(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
>>As Long, _
>>lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
>>As Long
>>
>>Public Function stdout()
>>
>>Dim sWriteBuffer As String
>>Dim lBytesWritten As Long
>>Dim hStdOut As Long
>>
>>
>>'Send something to stdout
>>sWriteBuffer = "This really sucks!" & vbCrLf
>>hStdOut = w32_stdout()
>>WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
>>
>>
>>
>>End Function
>>
>>Any suggestions on how to return a value to the command line via stdout
>or
>>another method? I hate to say it but in C this is cake. Why does it have
>>to be so hard in VB.
>>
>>Thanks!
>
-
Re: stdout -- Why is it so hard?
This article is essentially a regurgitation of Q239588. The problem is that
it doesn't actually write back to the shell. If you take the code provided
in the article... it doesn't return anything to the shell. If it is calling
a new command shell then it can do it no problem. It looks like the problem
is obtaining the valid handle. Still not sure what to do.
Thanks!
Joe
"Monte Hansen" <monte@nospam.com> wrote:
>
>http://www.win2000mag.com/Articles/I...cleID=565&pg=1
>
>+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
>Monte Hansen
>http://KillerVB.com
>+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
>
>
>
>"Joe Shields" <joe.shields@wellsfargo.com> wrote:
>>
>>So I am trying to pass a value back to stdout after executing a VB application
>>with command switches from command line. Although it appears to get a valid
>>handle, nothing is returned to the shell session.
>>
>>Here is what I am doing.....
>>
>>Option Explicit
>>
>>Public Const STD_OUTPUT_HANDLE = -11&
>>
>>Public Declare Function w32_stdout Lib "kernel32" Alias "GetStdHandle"
_
>>(Optional ByVal Handletype As Long = STD_OUTPUT_HANDLE) As Long
>>
>>Public Declare Function WriteFile Lib "kernel32" _
>>(ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite
>>As Long, _
>>lpNumberOfBytesWritten As Long, Optional ByVal lpOverlapped As Long = 0&)
>>As Long
>>
>>Public Function stdout()
>>
>>Dim sWriteBuffer As String
>>Dim lBytesWritten As Long
>>Dim hStdOut As Long
>>
>>
>>'Send something to stdout
>>sWriteBuffer = "This really sucks!" & vbCrLf
>>hStdOut = w32_stdout()
>>WriteFile hStdOut, sWriteBuffer, Len(sWriteBuffer) + 1, lBytesWritten
>>
>>
>>
>>End Function
>>
>>Any suggestions on how to return a value to the command line via stdout
>or
>>another method? I hate to say it but in C this is cake. Why does it have
>>to be so hard in VB.
>>
>>Thanks!
>
-
Re: stdout -- Why is it so hard?
> Any suggestions on how to return a value to the command line via stdout or
> another method? I hate to say it but in C this is cake. Why does it have
> to be so hard in VB.
Because in C you are creating a console application, and in VB you are creating a windows
application.
After compiling your windows app, you can run editbin.exe with the /subsystem:console
switch on your binary to turn it into a console app. Your stdout functionality should work
as expected.
Regards,
Pete Young
-
Re: stdout -- Why is it so hard?
> Any suggestions on how to return a value to the command line via stdout or
> another method? I hate to say it but in C this is cake. Why does it have
> to be so hard in VB.
Because in C you are creating a console application, and in VB you are creating a windows
application.
After compiling your windows app, you can run editbin.exe with the /subsystem:console
switch on your binary to turn it into a console app. Your stdout functionality should work
as expected.
Regards,
Pete Young
-
Re: stdout -- Why is it so hard?
Mr. Young... you rock!
Worked perfectly!
BTW, is this what happens behind the scene when you make a conssole application
in VC++?
Joe
"Peter Young" <TubeCrunch@telocity.com.nospam> wrote:
>> Any suggestions on how to return a value to the command line via stdout
or
>> another method? I hate to say it but in C this is cake. Why does it have
>> to be so hard in VB.
>
>Because in C you are creating a console application, and in VB you are creating
a windows
>application.
>
>After compiling your windows app, you can run editbin.exe with the /subsystem:console
>switch on your binary to turn it into a console app. Your stdout functionality
should
>work
>as expected.
>
>Regards,
>
>Pete Young
>
>
-
Re: stdout -- Why is it so hard?
Mr. Young... you rock!
Worked perfectly!
BTW, is this what happens behind the scene when you make a conssole application
in VC++?
Joe
"Peter Young" <TubeCrunch@telocity.com.nospam> wrote:
>> Any suggestions on how to return a value to the command line via stdout
or
>> another method? I hate to say it but in C this is cake. Why does it have
>> to be so hard in VB.
>
>Because in C you are creating a console application, and in VB you are creating
a windows
>application.
>
>After compiling your windows app, you can run editbin.exe with the /subsystem:console
>switch on your binary to turn it into a console app. Your stdout functionality
should
>work
>as expected.
>
>Regards,
>
>Pete Young
>
>
-
Re: stdout -- Why is it so hard?
> Mr. Young... you rock!
Well, I used to, but now I just write code. :-)
> BTW, is this what happens behind the scene when you make a conssole application
> in VC++?
Yep.
-Pete
-
Re: stdout -- Why is it so hard?
> Mr. Young... you rock!
Well, I used to, but now I just write code. :-)
> BTW, is this what happens behind the scene when you make a conssole application
> in VC++?
Yep.
-Pete
-
Re: stdout -- Why is it so hard?
Joe,
> So I am trying to pass a value back to stdout after executing a VB
application
> with command switches from command line. Although it appears to get a
valid
> handle, nothing is returned to the shell session.
If you want a complete code example of how to create a console app in VB,
look at my web site (below)... It has code for an article I did for VBPJ.
With a few extra lines of code (examples given), you can also have your VB
console app do redirection and piping.
--
L.J. Johnson, Slightly Tilted Software
Microsoft MVP (Visual Basic)
LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
<http://www.SlightlyTiltedSoftware.com>
Ask The NT Pro at <http://www.devx.com/gethelp>
-
Re: stdout -- Why is it so hard?
Joe,
> So I am trying to pass a value back to stdout after executing a VB
application
> with command switches from command line. Although it appears to get a
valid
> handle, nothing is returned to the shell session.
If you want a complete code example of how to create a console app in VB,
look at my web site (below)... It has code for an article I did for VBPJ.
With a few extra lines of code (examples given), you can also have your VB
console app do redirection and piping.
--
L.J. Johnson, Slightly Tilted Software
Microsoft MVP (Visual Basic)
LJJohnson@SlightlyTiltedSoftware.com or LJJohnson@mvps.org
<http://www.SlightlyTiltedSoftware.com>
Ask The NT Pro at <http://www.devx.com/gethelp>
-
Re: stdout -- Why is it so hard?
This won't help you with the code (you've gotten plenty of help on that),
but it will help you with the build process.
This request comes in often enough that I figured I would put together an
add-in to do the equivalent of the EditBin step. No fancy UI, but it works
great for either a Make Exe or a command line build, and you don't need a
separate EditBin step.
http://www.PowerVB.com/ConsoleApp.htm
-Matt
-
Re: stdout -- Why is it so hard?
This won't help you with the code (you've gotten plenty of help on that),
but it will help you with the build process.
This request comes in often enough that I figured I would put together an
add-in to do the equivalent of the EditBin step. No fancy UI, but it works
great for either a Make Exe or a command line build, and you don't need a
separate EditBin step.
http://www.PowerVB.com/ConsoleApp.htm
-Matt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|