Shell commands in ASP.NET?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allan Rojas

    Shell commands in ASP.NET?

    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 = ExecuteShellCom mand("dir *.txt");

    thnx in advance...



  • dave wanta

    #2
    Re: Shell commands in ASP.NET?

    You want to look at the System.Diagnost ics.Process namespace.


    Cheers!
    Dave




    "Allan Rojas" <ndrtkr@thecqgl .com> wrote in message
    news:enmRuDYQDH A.4024@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi,
    >
    > I want to execute a shell command and retrieve the output of it, is there[/color]
    a[color=blue]
    > method to do it? All i have found is how to start a process (cmd /C), but[/color]
    i[color=blue]
    > cannot retrieve the result of the command execution.
    >
    > For example, it would be ideal if there would be a method like:
    >
    > string result = ExecuteShellCom mand("dir *.txt");
    >
    > thnx in advance...
    >
    >
    >[/color]


    Comment

    • Allan Rojas

      #3
      Re: Shell commands in ASP.NET?

      I already did; but when executing the following code, i get a
      System.InvalidO perationExcepti on: StandardOut has not been redirected.


      System.Diagnost ics.Process myP = System.Diagnost ics.Process.Sta rt("cmd",
      @"/C dir C:\");
      Response.Output .Write(myP.Stan dardOutput.Read ToEnd());

      Thnx in advance...


      "dave wanta" <nospam@nospam. com> wrote in message
      news:O3FSbIYQDH A.560@TK2MSFTNG P10.phx.gbl...[color=blue]
      > You want to look at the System.Diagnost ics.Process namespace.
      >
      >
      > Cheers!
      > Dave
      > www.aspNetEmail.com
      >
      >
      >
      > "Allan Rojas" <ndrtkr@thecqgl .com> wrote in message
      > news:enmRuDYQDH A.4024@tk2msftn gp13.phx.gbl...[color=green]
      > > Hi,
      > >
      > > I want to execute a shell command and retrieve the output of it, is[/color][/color]
      there[color=blue]
      > a[color=green]
      > > method to do it? All i have found is how to start a process (cmd /C),[/color][/color]
      but[color=blue]
      > i[color=green]
      > > cannot retrieve the result of the command execution.
      > >
      > > For example, it would be ideal if there would be a method like:
      > >
      > > string result = ExecuteShellCom mand("dir *.txt");
      > >
      > > thnx in advance...
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • dave wanta

        #4
        Re: Shell commands in ASP.NET?

        you probably need to set

        myP.StartInfo.R edirectStandard Output = true;

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

        hth,
        Dave


        "Allan Rojas" <ndrtkr@thecqgl .com> wrote in message
        news:eN4FPSYQDH A.1040@TK2MSFTN GP12.phx.gbl...[color=blue]
        > I already did; but when executing the following code, i get a
        > System.InvalidO perationExcepti on: StandardOut has not been redirected.
        >
        >
        > System.Diagnost ics.Process myP = System.Diagnost ics.Process.Sta rt("cmd",
        > @"/C dir C:\");
        > Response.Output .Write(myP.Stan dardOutput.Read ToEnd());
        >
        > Thnx in advance...
        >
        >
        > "dave wanta" <nospam@nospam. com> wrote in message
        > news:O3FSbIYQDH A.560@TK2MSFTNG P10.phx.gbl...[color=green]
        > > You want to look at the System.Diagnost ics.Process namespace.
        > >
        > >
        > > Cheers!
        > > Dave
        > > www.aspNetEmail.com
        > >
        > >
        > >
        > > "Allan Rojas" <ndrtkr@thecqgl .com> wrote in message
        > > news:enmRuDYQDH A.4024@tk2msftn gp13.phx.gbl...[color=darkred]
        > > > Hi,
        > > >
        > > > I want to execute a shell command and retrieve the output of it, is[/color][/color]
        > there[color=green]
        > > a[color=darkred]
        > > > method to do it? All i have found is how to start a process (cmd /C),[/color][/color]
        > but[color=green]
        > > i[color=darkred]
        > > > cannot retrieve the result of the command execution.
        > > >
        > > > For example, it would be ideal if there would be a method like:
        > > >
        > > > string result = ExecuteShellCom mand("dir *.txt");
        > > >
        > > > thnx in advance...
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...