can C# perform command prompt lines

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 84
Reputation: knowledgelover is an unknown quantity at this point 
Solved Threads: 0
knowledgelover knowledgelover is offline Offline
Junior Poster in Training

can C# perform command prompt lines

 
0
  #1
Apr 13th, 2008
Hi there,

Can C# code , execute commands we write in the cmd window ?
i.e: is there a way to let a C# application interact in somehow the command prompt?

example : we use the command prompt line: ipconfig to see info about the IP address of the machine, can I execute this command from the C#? (I now that there is a way in C# to get the IP address but this is not what I want , the ip address is just an example)

Thanks in advance
there's always something to learn
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: can C# perform command prompt lines

 
0
  #2
Apr 13th, 2008
Here is an example. You can also tack on a p.WaitForExit(); if needed.

  1. using System.Diagnostics;
  2. .
  3. .
  4. .
  5. Process p = new Process();
  6. p.StartInfo.FileName = "IPCONFIG";
  7. p.StartInfo.UseShellExecute = false;
  8. p.StartInfo.Arguments = "/all";
  9. p.StartInfo.RedirectStandardOutput = true;
  10. p.Start();
  11. textBox1.Text = p.StandardOutput.ReadToEnd();

// Jerry
if this solves your issue, please remember to mark it as solved.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: knowledgelover is an unknown quantity at this point 
Solved Threads: 0
knowledgelover knowledgelover is offline Offline
Junior Poster in Training

Re: can C# perform command prompt lines

 
0
  #3
Apr 13th, 2008
Originally Posted by JerryShaw View Post
Here is an example. You can also tack on a p.WaitForExit(); if needed.

  1. using System.Diagnostics;
  2. .
  3. .
  4. .
  5. Process p = new Process();
  6. p.StartInfo.FileName = "IPCONFIG";
  7. p.StartInfo.UseShellExecute = false;
  8. p.StartInfo.Arguments = "/all";
  9. p.StartInfo.RedirectStandardOutput = true;
  10. p.Start();
  11. textBox1.Text = p.StandardOutput.ReadToEnd();
is this supose to work with all kind of commands , like cd , when I tried it, I did not see the folder opened , i.e there are some commands has no return output but has actions , what should I do to see them ,

Thanks
there's always something to learn
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: can C# perform command prompt lines

 
0
  #4
Apr 13th, 2008
DOS commands occur in "that" process. So, the cmdshell does accept the and act upon the CD directive, however, once that command shell closes, the process of changing directories has nothing to do with the next command shell directive because it would be in a new shell.

Maybe what you are looking for can be found at this URL
http://www.codeproject.com/KB/miscct...andprompt.aspx
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: raaams is an unknown quantity at this point 
Solved Threads: 1
raaams raaams is offline Offline
Newbie Poster

Re: can C# perform command prompt lines

 
0
  #5
Jan 15th, 2009
using System.Diagnostics;
.
.
.
Process p = new Process();
p.StartInfo.FileName = "IPCONFIG";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "/all";
p.StartInfo.RedirectStandardOutput = true;
p.Start();
textBox1.Text = p.StandardOutput.ReadToEnd();

This code Works Fantastically fulfilling my present need...
Thank u Jerry
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: can C# perform command prompt lines

 
0
  #6
Jan 15th, 2009
Dont forget then to mark this as solved
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: knowledgelover is an unknown quantity at this point 
Solved Threads: 0
knowledgelover knowledgelover is offline Offline
Junior Poster in Training

Re: can C# perform command prompt lines

 
0
  #7
Jan 25th, 2009
Thank you Jerry
it was really helpful
and I got the needed work done
thanks again
there's always something to learn
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC