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...You want to look at the System.Diagnostics.Process namespace.
Cheers!
Dave
www.aspNetEmail.com
"Allan Rojas" <ndrtkr@.thecqgl.com> wrote in message
news:enmRuDYQDHA.4024@.tk2msftngp13.phx.gbl...
> 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...
"dave wanta" <nospam@.nospam.com> wrote in message
news:O3FSbIYQDHA.560@.TK2MSFTNGP10.phx.gbl...
> You want to look at the System.Diagnostics.Process namespace.
>
> Cheers!
> Dave
> www.aspNetEmail.com
>
> "Allan Rojas" <ndrtkr@.thecqgl.com> wrote in message
> news:enmRuDYQDHA.4024@.tk2msftngp13.phx.gbl...
> > 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...
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
"Allan Rojas" <ndrtkr@.thecqgl.com> wrote in message
news:eN4FPSYQDHA.1040@.TK2MSFTNGP12.phx.gbl...
> 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...
>
> "dave wanta" <nospam@.nospam.com> wrote in message
> news:O3FSbIYQDHA.560@.TK2MSFTNGP10.phx.gbl...
> > You want to look at the System.Diagnostics.Process namespace.
> > Cheers!
> > Dave
> > www.aspNetEmail.com
> > "Allan Rojas" <ndrtkr@.thecqgl.com> wrote in message
> > news:enmRuDYQDHA.4024@.tk2msftngp13.phx.gbl...
> > > 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...
> > >
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment