473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

STD_OUTPUT_HANDLE

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
7 3977
* 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
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
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
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
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
Thanks Tom.

Understanding goes up another notch. :-)

Regards,
Fergus
Nov 20 '05 #7
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method:...
16
by: Chris Maloof | last post by:
Hello, Does anyone know how I can read the ASCII text from a console window (from another application) in WinXP? It doesn't sound like a major operation, but although I can find the window via...
7
by: Joe C | last post by:
I'd like to have better control of text output to the console. I'm using Windows and have a little (non-standard) function to help me out: #include <windows.h> void locate(int x, int y ) {...
10
by: Stefano Camaiani | last post by:
Hello, it's strange but in the web there are not (or i found not) explanation on howto use ReadConsoleOutputCharacter from C# or Vb.Net.... Very much articles, but not one word of this particular...
1
by: Stefano Camaiani | last post by:
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...
2
by: Maverick | last post by:
I'm implementing the functions of WriteConsoleOutput and ReadConsleOutput output. The "WriteConsoleOutput" can be work properly ....but the output of "ReadConsoleOutput" is wrong anyway .... can...
2
by: Doug Perkes | last post by:
There was a post a couple of months ago entitled "ReadConsoleOutput - ReadConsoleOutputCharacter APIs". I have some questions in relation to that post. I have an existing console application...
9
by: Dragon | last post by:
Hello all, I ran into trouble with GetStdHandle API. When I'm trying to get standard output with GetStdHandle(-11I), it returns strange values such as 1548, 1876. If I try to WriteConsole() into...
0
by: shadowsoulja | last post by:
okay, ive been going okay on my assignment, but ive just run into a problem. i need to read a file into my program, the data from the file is to be read, and then randomised to produce "match...
6
cassyhoz
by: cassyhoz | last post by:
Hi, I was asked in school to make this sort of videogame in C basic where a little bar defends a city (which is in the bottom) from falling thunders. I'm working on Visual Basic 2005 and this is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.