Help - Search - Members - Calendar
Full Version: Handling Command Line Programs In VB
Hydrogenaudio Forums > Misc. > Off-Topic
tool++
MODS: Please move this to Development and delete this message, thanks!!

What would be the best way of running a command line app from within a VB program and displaying its output in a form (eg in a txtbox)?


Here's a simple example, for clarity: Say I have a form that has a box that you put an IP address in, it will run ping <ip> and then the output will appear as it is recieved in a little box ON THE FORM.

I've seen this done in apps a lot.

Any ideas?
Thanks :]
mquander
QUOTE(tool++ @ Nov 19 2006, 17:20) *

MODS: Please move this to Development and delete this message, thanks!!

What would be the best way of running a command line app from within a VB program and displaying its output in a form (eg in a txtbox)?


Here's a simple example, for clarity: Say I have a form that has a box that you put an IP address in, it will run ping <ip> and then the output will appear as it is recieved in a little box ON THE FORM.

I've seen this done in apps a lot.

Any ideas?
Thanks :]


If you're using VB6, you're looking for the Shell() function (as I recall, but it's been years.)

If you're using VB.NET, you're looking for the System.Diagnostics.Process.Start() method.

Edit: Actually, maybe that's not what you're having problems with; perhaps you know how to run the ping utility, but you are wondering how to get the output that would normally appear on the console onto your form? I can't think of any realistic way to do that. When you run an external process, unless it's written in a way specifically to interact with your application, probably the only direct feedback you will be able to receive is the exit error code, which in the case of ping, probably tells whether the ping got there or whether it timed out.

The correct way to do this is just to use your application to ping the IP address yourself.

EDIT: Oh, clever! c0utta's solution will probably work for most simple command line applications.
c0utta
Hi tool++,

I've done this using VB.NET by creating a Process and attaching a StreamReader to the StandardOutput stream of the process. The output from the Process (i.e. the PING) is then available via the ReadToEnd() method.

I was only interested in the whole output once the process was complete, so I'm not sure whether you can grab each individual output as it occurs.

HTH,

c0utta
foosion
QUOTE(tool++ @ Nov 19 2006, 23:20) *
MODS: Please move this to Development and delete this message, thanks!!
This doesn't seem to have much to do with the development of foobar2000 components, so I've moved it to Offtopic. By the way, the easiest way to ensure that a moderator will see your request to move a thread is to report the starting post. Despite any scary-looking warning you might get when using the report post feature, this is the recommended way for dealing with this kind of issue.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.