Controlling a console application from another application.

P

Paulers

Hello,

I am trying to manipulate a console based application from another
application for example I need to launch the console application,
provide it input and take the output from the console application and
use it within my application. Is this possible with vb.net? If so
could someone point me in the right direction. Thank you :)
 
C

CMoya

Quick thought. Have the console app monitor a txt file using the
FileSystemWatcher control. Pass (and return)commands to it via that file.
Just an idea.

The only other way would be via Remoting (the equivalent of old VB's ActiveX
Exe servers), which would allow you to call functions in the already running
process. Remoting is too tough to explain in a post. You can do a Google
search to find articles on it.
 
P

Paulers

Quick thought. Have the console app monitor a txt file using the
FileSystemWatcher control. Pass (and return)commands to it via that file.
Just an idea.

The only other way would be via Remoting (the equivalent of old VB's ActiveX
Exe servers), which would allow you to call functions in the already running
process. Remoting is too tough to explain in a post. You can do a Google
search to find articles on it.

Thanks for the reply. The only issue is that the console application
is not mine. I just want to be able to control it from my application
and use it's output.
 
M

Michael D. Ober

Paulers said:
Thanks for the reply. The only issue is that the console application
is not mine. I just want to be able to control it from my application
and use it's output.

Take a look at input/output redirection. Before coding this, you can test
redirection from the command line.

Mike.
 
T

Tom Shelton

Hello,

I am trying to manipulate a console based application from another
application for example I need to launch the console application,
provide it input and take the output from the console application and
use it within my application. Is this possible with vb.net? If so
could someone point me in the right direction. Thank you :)

You can use system.diagnostics.process to start the app, and then
redirect it's input and output to streams in your process. Then you
can read and write to it.
 
K

kimiraikkonen

Hello,

I am trying to manipulate a console based application from another
application for example I need to launch the console application,
provide it input and take the output from the console application and
use it within my application. Is this possible with vb.net? If so
could someone point me in the right direction. Thank you :)

You can redirect command prompt's output to an Win32 app's object
within your project:

Here is a sample returns "dir" command prompt result into a textbox:

Place a textbox(textbox1) and a button(button1) for these
demonstration:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim start_info As New ProcessStartInfo("cmd.exe", "/c dir")
start_info.UseShellExecute = False
start_info.CreateNoWindow = True
start_info.RedirectStandardOutput = True
start_info.RedirectStandardError = True

' Make the process and set its start information.
Dim proc As New Process()
proc.StartInfo = start_info

' Start the process.
proc.Start()

' Attach to stdout and stderr.
Dim std_out As IO.StreamReader = proc.StandardOutput()


' Display the results.
TextBox1.Text = std_out.ReadToEnd()


' Clean up.
std_out.Close()

proc.Close()
End Sub
End Class


Hope this helps.
 

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