473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to process a command response in C#?

13
Hi,

Just wondering if anyone knows how to process a command response, such as a "ping", in C#? For example, I know if you make the call, using the System.Diagnostics namespace, "Process process = Process.Start("cmd", "/C ping localhost > ping.txt");" starts the command prompt and runs the ping command and then stores the output into the ping.txt file. I'm just wondering if there's a way to avoid the copying of the output to a text file, and routing it to a local string variable in my code, so that I can process it directly? Or is processing the output via the text file the only way?

Thanks in advanced!
-Weeg
Mar 13 '08 #1
1 3612
r035198x
13,262 8TB
Hi,

Just wondering if anyone knows how to process a command response, such as a "ping", in C#? For example, I know if you make the call, using the System.Diagnostics namespace, "Process process = Process.Start("cmd", "/C ping localhost > ping.txt");" starts the command prompt and runs the ping command and then stores the output into the ping.txt file. I'm just wondering if there's a way to avoid the copying of the output to a text file, and routing it to a local string variable in my code, so that I can process it directly? Or is processing the output via the text file the only way?

Thanks in advanced!
-Weeg
Expand|Select|Wrap|Line Numbers
  1. Process p = new Process();
  2.             p.StartInfo.FileName = "COMMAND";
  3.             p.StartInfo.Arguments = file;
  4.             p.StartInfo.UseShellExecute = false;
  5.             p.StartInfo.RedirectStandardOutput = true;
  6.             p.Start();
  7.             String output = p.StandardOutput.ReadToEnd();
Mar 13 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
2
by: Bob Murdoch | last post by:
I'm developing an intranet application using W2k server and IE5.5 - 6.x clients. I've got one particular function that calls a stored procedure to update a number of records, depending on user...
1
by: Div / | last post by:
I have a very strange problem here. I have a wrapper class for a command line MyProgram.exe. When i run it from the command prompt (MyProgram.exe), it runs perfectly. So there is not problem with...
6
by: jcrouse | last post by:
This is kind of a continuation of another thread that was somewhat resolved: Well, the dilemma seems to be this. I want to be able to hide the DOS box AND pause the code until execution is...
7
by: RSH | last post by:
Hi, I have an ASP .Net web page that creates a temp directory on the server then it is using the File.Copy command to move a file to a temp download directory, Then I am doing a...
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
5
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the...
4
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
I am at my witless end here, please help! I have an ASP.Net aspx web page, hosted on Windows Server 2003, that receives a query string with the path to an autocad drawing file selected from a...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.