Shell commands in ASP.NET?

  • Thread starter Thread starter Allan Rojas
  • Start date Start date
A

Allan Rojas

Hi,

I want to execute a shell command and retrieve the output of it, is there a
method to do it? All i have found is how to start a process (cmd /C), but i
cannot retrieve the result of the command execution.

For example, it would be ideal if there would be a method like:

string result = ExecuteShellCommand("dir *.txt");

thnx in advance...
 
I already did; but when executing the following code, i get a
System.InvalidOperationException: StandardOut has not been redirected.


System.Diagnostics.Process myP = System.Diagnostics.Process.Start("cmd",
@"/C dir C:\");
Response.Output.Write(myP.StandardOutput.ReadToEnd());

Thnx in advance...
 
you probably need to set

myP.StartInfo.RedirectStandardOutput = true;

btw, if you only want to list out files, i would recommend the System.IO
namespace.

hth,
Dave
www.aspNetEmail.com
 
Back
Top