Shell commands in ASP.NET?

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...
 
A

Allan Rojas

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...
 
D

dave wanta

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top