How to run multiple lines of code through a Process?

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

    #1

    How to run multiple lines of code through a Process?

    I'm using a Process object to run cmd and I give it the text from a textbox.
    It only executes the first line i.e. the first command.
    Is there some way to tell cmd to keep executing.

    I could write the text to a file and run that but that's a bit of a kluge.

    Any suggestions?



  • active

    #2
    Re: How to run multiple lines of code through a Process?

    I have it working now.


    " active" <activeNOSPAM @a-znet.comwrote in message
    news:eWfw6tUUHH A.1552@TK2MSFTN GP05.phx.gbl...
    I'm using a Process object to run cmd and I give it the text from a
    textbox.
    It only executes the first line i.e. the first command.
    Is there some way to tell cmd to keep executing.
    >
    I could write the text to a file and run that but that's a bit of a kluge.
    >
    Any suggestions?
    >
    >
    >

    Comment

    • RobinS

      #3
      Re: How to run multiple lines of code through a Process?

      Write the text to a batch file (.bat) and run that.

      Robin S.
      ---------------------
      " active" <activeNOSPAM @a-znet.comwrote in message
      news:eWfw6tUUHH A.1552@TK2MSFTN GP05.phx.gbl...
      I'm using a Process object to run cmd and I give it the text from a
      textbox.
      It only executes the first line i.e. the first command.
      Is there some way to tell cmd to keep executing.
      >
      I could write the text to a file and run that but that's a bit of a
      kluge.
      >
      Any suggestions?
      >
      >
      >

      Comment

      • RobinS

        #4
        Re: How to run multiple lines of code through a Process?

        Well, come on, tell us how. Think of the next poor guy who tries to figure
        out how to do this, and searches this newsgroup and finds your post! How
        excited he will be! Until he reads the second post and finds you didn't
        post the answer. Oh, the depression! Oh, the agony! ;-)

        Robin S.
        ----------------------------
        " active" <activeNOSPAM @a-znet.comwrote in message
        news:eHHpkgVUHH A.1180@TK2MSFTN GP05.phx.gbl...
        >I have it working now.
        >
        >
        " active" <activeNOSPAM @a-znet.comwrote in message
        news:eWfw6tUUHH A.1552@TK2MSFTN GP05.phx.gbl...
        >I'm using a Process object to run cmd and I give it the text from a
        >textbox.
        >It only executes the first line i.e. the first command.
        >Is there some way to tell cmd to keep executing.
        >>
        >I could write the text to a file and run that but that's a bit of a
        >kluge.
        >>
        >Any suggestions?
        >>
        >>
        >>
        >
        >

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: How to run multiple lines of code through a Process?

          " active" <activeNOSPAM @a-znet.comschrieb :
          I'm using a Process object to run cmd and I give it the text from a
          textbox.
          It only executes the first line i.e. the first command.
          Is there some way to tell cmd to keep executing.
          <URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole .zip>

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          • active

            #6
            Re: How to run multiple lines of code through a Process?

            I had an error in the command data .

            The problem I originally described did not exist - it only seemed to because
            I had a error in the first line and was not redirecting the errors

            cod seems to run one line at a time from the textbox.text string.




            "RobinS" <RobinS@NoSpam. yah.nonewrote in message
            news:e7udnafZGO sIZknYnZ2dnUVZ_ hKdnZ2d@comcast .com...
            Well, come on, tell us how. Think of the next poor guy who tries to figure
            out how to do this, and searches this newsgroup and finds your post! How
            excited he will be! Until he reads the second post and finds you didn't
            post the answer. Oh, the depression! Oh, the agony! ;-)
            >
            Robin S.
            ----------------------------
            " active" <activeNOSPAM @a-znet.comwrote in message
            news:eHHpkgVUHH A.1180@TK2MSFTN GP05.phx.gbl...
            >>I have it working now.
            >>
            >>
            >" active" <activeNOSPAM @a-znet.comwrote in message
            >news:eWfw6tUUH HA.1552@TK2MSFT NGP05.phx.gbl.. .
            >>I'm using a Process object to run cmd and I give it the text from a
            >>textbox.
            >>It only executes the first line i.e. the first command.
            >>Is there some way to tell cmd to keep executing.
            >>>
            >>I could write the text to a file and run that but that's a bit of a
            >>kluge.
            >>>
            >>Any suggestions?
            >>>
            >>>
            >>>
            >>
            >>
            >
            >

            Comment

            • active

              #7
              Re: How to run multiple lines of code through a Process?

              Even if I think it a kluge (see below).

              seriously, thanks for replying


              "RobinS" <RobinS@NoSpam. yah.nonewrote in message
              news:tpOdncIZrZ DnZ0nYnZ2dnUVZ_ rOqnZ2d@comcast .com...
              Write the text to a batch file (.bat) and run that.
              >
              Robin S.
              ---------------------
              " active" <activeNOSPAM @a-znet.comwrote in message
              news:eWfw6tUUHH A.1552@TK2MSFTN GP05.phx.gbl...
              >I'm using a Process object to run cmd and I give it the text from a
              >textbox.
              >It only executes the first line i.e. the first command.
              >Is there some way to tell cmd to keep executing.
              >>
              >I could write the text to a file and run that but that's a bit of a
              >kluge.
              >>
              >Any suggestions?
              >>
              >>
              >>
              >
              >

              Comment

              • active

                #8
                Re: How to run multiple lines of code through a Process?

                I'll look.
                I'm sure it's more comprehensive then what I did.
                I tend to have trouble understanding a lot of your published code's
                comments.
                I'm thinking it would be worthwhile to study German! :)
                Thanks



                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
                news:uNllg6WUHH A.2256@TK2MSFTN GP02.phx.gbl...
                >" active" <activeNOSPAM @a-znet.comschrieb :
                >I'm using a Process object to run cmd and I give it the text from a
                >textbox.
                >It only executes the first line i.e. the first command.
                >Is there some way to tell cmd to keep executing.
                >
                <URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole .zip>
                >
                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                Comment

                • active

                  #9
                  Re: How to run multiple lines of code through a Process?

                  Just as I thought - your code is more comprehensive.

                  Much the same as what I did except that I streamed in to and out of the
                  process directly.

                  Why did you use subs to do that.

                  If it is because you wanted to use threads - why did you feel the need for
                  threads?


                  Thanks for the code

                  PS I'm not real comfortable with streams yet.

                  I'd appreciate it if you looked at the code below and critized anything that
                  is not as you'd do it.

                  Especially the use of SROut and SWOut - I wasn't sure how to read the output
                  and write it to a file?


                  thanks in advance


                  Dim StartInfo As New ProcessStartInf o

                  Static myProcess As New Process

                  StartInfo.FileN ame = "cmd"

                  StartInfo.Redir ectStandardInpu t = True

                  StartInfo.Redir ectStandardOutp ut = True

                  StartInfo.Creat eNoWindow = True

                  StartInfo.UseSh ellExecute = False

                  myProcess.Start Info = StartInfo

                  myProcess.Start ()

                  Dim SWIn As System.IO.Strea mWriter = myProcess.Stand ardInput

                  SWIn.WriteLine( ControlTextEdit orIn.Text)

                  SWIn.WriteLine( "exit")

                  Dim SROut As System.IO.Strea mReader = myProcess.Stand ardOutput

                  With OpenFileDialog1

                  ...snip..

                  Dim SWOut As New System.IO.Strea mWriter(.FileNa me)

                  SWOut.WriteLine (SROut.ReadToEn d)

                  myProcess.WaitF orExit()

                  SWOut.Close()

                  Registry.SetVal ue(mSubKey, "Executed File", .FileName)

                  End If

                  End With

                  SWIn.Close()

                  SROut.Close()






                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
                  news:uNllg6WUHH A.2256@TK2MSFTN GP02.phx.gbl...
                  >" active" <activeNOSPAM @a-znet.comschrieb :
                  >I'm using a Process object to run cmd and I give it the text from a
                  >textbox.
                  >It only executes the first line i.e. the first command.
                  >Is there some way to tell cmd to keep executing.
                  >
                  <URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole .zip>
                  >
                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                  Comment

                  Working...