Read text from console app using vb.net?


A

Andrius B.

Hi guys.

I have such a task.
I am developing a VB.NET app (as WindowsExe application, not console) to
work with Oracle DB.
To retrieve the data, I use such method: call PLUS80.EXE, witch takes db
username and password, connects to db, executes given SQL script and writes
data to CSV files.
PLUS80.EXE is a console app, I call it using SHELL command in vb.net:

Shell("PLUS80 " & User & "/" & Pass & " @export.sql", AppWinStyle.Hide,
True)

So, PLUS80 executes in a hidden window, in order to simplify the work with
my app (not to confuse user with pop-up windows). And the main app waits
till PLUS80 finishes.
If smth goes wrong, e.g. bad username or password is given, PLUS throws an
exception (like ORA-xxxxx: some text) and waits for user actions (e.g. enter
password manually). The problem is, that is such a case PLUS80 "freezes",
and the main app also freezes waiting for PLUS80 exiting. User can do
nothing, because it sees nothing - the PLUS80 window is hidden.

So, I'd like to have a tool to enable my main app to retrieve the text from
PLUS80 window (that means, the text from that console window that is
outputed). Then I'll be able to strip from all that text the line containing
string like "ORA-xxxxx", and show it to the user by using MsgBox.
And the second part, i need a tool to send some text to console (like "exit"
command, witch will end PLUS80, and my main app "unfreezes"), imitating
pressing the
keyboard keys ending with "Enter" key pressing.

I know how to retrieve the handle of console window using FindWindow API,
but that's all.
I heard there are functions smth like ReadConcoleText, but no egamples how
to use it from an VB.NET

The main app is designet to work on Windows 2000 and Windows XP.


Thanks for any idea.
 
Ad

Advertisements

T

Tom Shelton

Hi guys.

I have such a task.
I am developing a VB.NET app (as WindowsExe application, not console) to
work with Oracle DB.
To retrieve the data, I use such method: call PLUS80.EXE, witch takes db
username and password, connects to db, executes given SQL script and writes
data to CSV files.
PLUS80.EXE is a console app, I call it using SHELL command in vb.net:

Shell("PLUS80 " & User & "/" & Pass & " @export.sql", AppWinStyle.Hide,
True)

So, PLUS80 executes in a hidden window, in order to simplify the work with
my app (not to confuse user with pop-up windows). And the main app waits
till PLUS80 finishes.
If smth goes wrong, e.g. bad username or password is given, PLUS throws an
exception (like ORA-xxxxx: some text) and waits for user actions (e.g. enter
password manually). The problem is, that is such a case PLUS80 "freezes",
and the main app also freezes waiting for PLUS80 exiting. User can do
nothing, because it sees nothing - the PLUS80 window is hidden.

So, I'd like to have a tool to enable my main app to retrieve the text from
PLUS80 window (that means, the text from that console window that is
outputed). Then I'll be able to strip from all that text the line containing
string like "ORA-xxxxx", and show it to the user by using MsgBox.
And the second part, i need a tool to send some text to console (like "exit"
command, witch will end PLUS80, and my main app "unfreezes"), imitating
pressing the
keyboard keys ending with "Enter" key pressing.

I know how to retrieve the handle of console window using FindWindow API,
but that's all.
I heard there are functions smth like ReadConcoleText, but no egamples how
to use it from an VB.NET

The main app is designet to work on Windows 2000 and Windows XP.


Thanks for any idea.

If you use the System.Diagnostics.Process class to work with the app, then you
can redirect it's IO so that you can read and write to it.
 
A

Andrius B.

Thanks Tom, that's a very usefull idea!

Tom Shelton said:
If you use the System.Diagnostics.Process class to work with the app, then
you
can redirect it's IO so that you can read and write to it.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top