Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / April 2006

Tip: Looking for answers? Try searching our database.

Is it possible to run a console function and capture the result.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken - 08 Apr 2006 23:25 GMT
I and not sure if this is the correct forum to post this queston.  Any ideas
will be appreciated.

Need to call a base windows console command function (like dir or chkdsk)
and capture the results for further processing.  

Two questions:
(1)  Is it possible to code a program in C# to do this?   -  I know everyone
says I should use Perl instead.
(2) Can I do it without reading or writing any files to disk?
Jon Shemitz - 09 Apr 2006 07:03 GMT
> Need to call a base windows console command function (like dir or chkdsk)
> and capture the results for further processing.
>
> Two questions:
> (1)  Is it possible to code a program in C# to do this?   -  I know everyone
> says I should use Perl instead.

Yes - you use the System.Diagnostics.Process class. (For a shell
command like dir, I think you'll have to run command.exe, and pass it
a "dir" argument - I haven't tried this.)

> (2) Can I do it without reading or writing any files to disk?

Yes.

Here's an example that I wrote (two days ago, fwiw) to capture PING
output:

private static string PingServer()
{
   Process Ping = new Process();
   Ping.StartInfo.UseShellExecute = false;
   Ping.StartInfo.FileName = "ping.exe";
   Ping.StartInfo.Arguments = @"-n 1 -r 9 www.midnightbeach.com";
   Ping.StartInfo.CreateNoWindow = true;
   Ping.StartInfo.RedirectStandardOutput = true;
   Ping.Start();
   return Ping.StandardOutput.ReadToEnd();
}

Signature

<http://www.midnightbeach.com>     Contracting, consulting, training
.NET 2.0 for Delphi Programmers  <http://www.midnightbeach.com/.net>
                                  In production - in stores by June


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.