2011-06-21 13 views
5

शैल के माध्यम से कमांड कमांड कैसे करें और सी # का उपयोग कर स्ट्रिंग के रूप में पूरा आउटपुट लौटाएं?सी # shell_exec

PHP के shell_exec() के बराबर।

धन्यवाद, उन्नत।

उत्तर

4

MSDN documentation on Process.StandardOutput प्रलेखन एक उदाहरण

// Start the child process. 
Process p = new Process(); 
// Redirect the output stream of the child process. 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.FileName = "Write500Lines.exe"; 
p.Start(); 
// Do not wait for the child process to exit before 
// reading to the end of its redirected stream. 
// p.WaitForExit(); 
// Read the output stream first and then wait. 
string output = p.StandardOutput.ReadToEnd(); 
p.WaitForExit(); 

साथ ही आप मानक त्रुटि धारा को निकालने के लिए पसंद कर सकते हैं दर्शाता है।

+0

ठीक काम करता है, धन्यवाद! –