By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

STD_OUTPUT_HANDLE

P: n/a
Hello, i need to find the STD_OUTPUT_HANDLE of a new process or a shelled
process...

I should not use standard redirections like MyProcess.StandardOutput....

I really need to find only this Handle: STD_OUTPUT_HANDLE...

In VB 6.0 if i call the AllocConsole API, this new console will show his new
handle by the API GetStdHandle(), but if i try to use AllocConsol within
VB.net or if i try to start a new process, the Handle returned is not the
handle of the created console but the same handle of the calling
application...

I hope of someone should understand my bad english..

Then this is: I need to find STD_OUTPUT_HANDLE of a created process or a
shelled console application from my Windows Based(GUI) application...
Thanks....

Stefano from Italy
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
* Stefano Camaiani schrieb:
Hello, i need to find the STD_OUTPUT_HANDLE of a new process or a shelled
process...

I should not use standard redirections like MyProcess.StandardOutput....

I really need to find only this Handle: STD_OUTPUT_HANDLE...

In VB 6.0 if i call the AllocConsole API, this new console will show his new
handle by the API GetStdHandle(), but if i try to use AllocConsol within
VB.net or if i try to start a new process, the Handle returned is not the
handle of the created console but the same handle of the calling
application...

I hope of someone should understand my bad english..

Then this is: I need to find STD_OUTPUT_HANDLE of a created process or a
shelled console application from my Windows Based(GUI) application...
Thanks....


Do you want to redirect Input/Output of the application to your .NET app?

<http://www.mvps.org/dotnet/dotnet/samples/miscsamples/downloads/RedirectConsole.zip>

--
Herfried K. Wagner
Microsoft MVP
<http://www.mvps.org/dotnet>

Nov 20 '05 #2

P: n/a
Hi Herfried, thanks for this code, but it is not what i'm searching
for...

It is good in 99% of cases but not for mine...

This code use the standard redirections wich is limitated to a PIPE
buffer between the created process and the StrinReader wich read the
output from the process.

If a process console don't terminate in few seconds or don't use the
NewLine(Vbcrlf) then this code should not get the Output before it
end...(Tak as example a CommandLine encoder like
WindowsMediaEncoder(Dos)

I'm searching for a way to get the STD_OUTPUT_HANDLE of the created
process to be able to use on it a buffer-free API call:
ReadConsoleOutput()

Thanks again....

Best regards, Stefano.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

P: n/a
In article <#d**************@tk2msftngp13.phx.gbl>, Stefano Camaiani wrote:
Hello, i need to find the STD_OUTPUT_HANDLE of a new process or a shelled
process...

I should not use standard redirections like MyProcess.StandardOutput....

I really need to find only this Handle: STD_OUTPUT_HANDLE...

In VB 6.0 if i call the AllocConsole API, this new console will show his new
handle by the API GetStdHandle(), but if i try to use AllocConsol within
VB.net or if i try to start a new process, the Handle returned is not the
handle of the created console but the same handle of the calling
application...

I hope of someone should understand my bad english..

Then this is: I need to find STD_OUTPUT_HANDLE of a created process or a
shelled console application from my Windows Based(GUI) application...
Thanks....

Stefano from Italy


Window programs do not have a stdin or stdout. When call the
AllocConsole API your allocating a console for your application. In
other words when you call GetStdHandle after calling allocconsole - you
are getting the handle for your process. This is just a guess, but
aparently, the VB6 version of shell uses the bInheritHandles flag for
it's call to createprocess. Which means, that the created or shell'd
process inherits your handles. It's the only way I can see that your
method would work in VB6.

I'm not sure why you can't use the System.Diagnostics.Process class to
redirect the output - your output does not have to be terminated by a
newline. You do have to know in that case when to close the streams -
but you can use Peek to check for output, Read to read a character at a
time, or ReadBlock to read in chunks... If you think you really need to
use ReadConsoleOutput then, if I were you I would use AllocConsole to
create the handles for your application, and then not use the VB.NET
shell command to start the process, but use CreateProcess directly,
passing True to the bInheritHandles parameter.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #4

P: n/a
Hi Tom,

I'm talking with only a liitle bit of knowledge gleamed from poking around
the Net this afternoon, so I could be way off base.

If Stefano has the Process Id for this console app, would
DuplicateHandle() be of any use?

Regards,
Fergus
Nov 20 '05 #5

P: n/a
In article <#W**************@TK2MSFTNGP09.phx.gbl>, Fergus Cooney wrote:
Hi Tom,

I'm talking with only a liitle bit of knowledge gleamed from poking around
the Net this afternoon, so I could be way off base.

If Stefano has the Process Id for this console app, would
DuplicateHandle() be of any use?

Regards,
Fergus


Yeah, it might. Though, it seems easier to me to just call
allocconsole, and then use createprocess to start the process. That
way, your child process handles are the same...

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #6

P: n/a
Thanks Tom.

Understanding goes up another notch. :-)

Regards,
Fergus
Nov 20 '05 #7

P: n/a
Thanks, this should be a cool way to get the output
handles....eheh...but i really don't know howto declare CreateProcess
and use it...

This is what i do:
<StructLayout(LayoutKind.Explicit, _ CharSet:=CharSet.Auto)> _
Public Structure STARTUPINFO
Public cb As Short
Public lpReserved As String
Public lpDesktop As String
Public lpTitle As String
Public dwX As Short
Public dwY As Short
Public dwXSize As Short
Public dwYSize As Short
Public dwXCountChars As Short
Public dwYCountChars As Short
Public dwFillAttribute As Short
Public dwFlags As Short
Public wShowWindow As Short
Public cbReserved2 As Short
Public lpReserved2 As Short
Public hStdInput As Short
Public hStdOutput As Short
Public hStdError As Short
End Structure

<StructLayout(LayoutKind.Explicit, _ CharSet:=CharSet.Auto)> _
Public Structure PROCESS_INFORMATION
Public hProcess As Short
Public hThread As Short
Public dwProcessId As Short
Public dwThreadId As Short
End Structure

<StructLayout(LayoutKind.Explicit, _ CharSet:=CharSet.Auto)> _
Public Structure SECURITY_ATTRIBUTES
Public nLength As Short
Public lpSecurityDescriptor As Short
Public bInheritHandle As Short
End Structure
Private Declare Auto Function CreateProcess Lib "kernel32" _
(ByVal lpApplicationName As String, ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As SECURITY_ATTRIBUTES, _
ByVal lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles
As Integer, _
ByVal dwCreationFlags As Integer, ByVal lpEnvironment As IntPtr, _
ByVal lpCurrentDriectory As String, ByVal lpStartupInfo As STARTUPINFO,
_
ByVal lpProcessInformation As PROCESS_INFORMATION) As Integer

But i really don't know hot to create the variables and hot to call the
CreateProcess function...

I understand of this is another question....one and one and one....but
please, i think of i should be, thank you you all, very near to get my
solution.

Thanks, Stefano.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.