views:

12

answers:

1

Hello,

I want to use SDelete after some code is run on an asp.net page. SDelete is a command line tool. My specific question is has anyone been able to run this SDelete from an asp.net page? More generic question would be, how do you run a command line utility from an asp.net page?

thanks

+1  A: 

You can run a command line utility using the Process Class

Process myProcess = new Process();

myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();

One more example closer to asp.net, that I wait to end, and read the output.

        Process compiler = new Process();

        compiler.StartInfo.FileName = "c:\\hello.exe";

        compiler.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;

        compiler.StartInfo.UseShellExecute = false;
        compiler.StartInfo.CreateNoWindow = false;

        compiler.StartInfo.RedirectStandardError = true;
        compiler.StartInfo.RedirectStandardOutput = true;
        compiler.StartInfo.RedirectStandardInput = true;

        // here I run it
        compiler.Start();

        compiler.StandardInput.Flush();
        compiler.StandardInput.Close();

        // here I get the output
        string cReadOutput = compiler.StandardOutput.ReadToEnd();

        compiler.WaitForExit();
        compiler.Close();
Aristos