Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hello all - I'm using vb8 - I'm having difficulty trying to figure out how to send a dos command to the console and output to a textwindow. I want to do this without having a console window open in the process - An example would be a simple form with one button and one text window - lets say the button was for "ipconfig" - when pressed it would simply display the "exact" output of the command prompt in the textwindow - also i want this to be down without the program referencing any external resources; such as batchfiles or writng to a textfile then reading from it - I've looked around on the web and havent found much that directly suits my need - I'm sure it can be done but with all of my noobishness I need some direction by the higher ups - this is a great site and i have found much help from it in the past and many thanks in advance to all who participate - if some would like to propose a resolution in c# - feel free

Here is one way
Dim p = New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.FileName = "ipconfig"
p.Start()
p.WaitForExit()
Dim output As String
output = p.StandardOutput.ReadToEnd()Console.Write(output)
in c#:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "ipconfig";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
They mostly come at night...mostly.

very nice - chi - a couple of questions though -
would I add this to the button click event?
and if i wanted to pass arguments to the ipconfig command such as "ipconfig /all" - would i include "process.StartInfo.Arguments = Arguments;"? - i found something similar here - http://www.codeproject.com/csharp/LaunchProcess.asp - from what i gather - i may not be able to add a second button performing a similar task due to multithreading issues? -Thanks again for your help

You can use the arguments property to set arguments and as far as multithreading...I don't know, I guess it all depends on what you are trying to launch. If you are using an XP system, then I think you should be able to multithread with no prob.
Chi
They mostly come at night...mostly.

![]() |
find large files recursiv...
|
Delphi 5 Question
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |