How to run multiple lines of code through a Process?

  • Thread starter Thread starter active
  • Start date Start date
A

active

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?
 
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.
----------------------------
 
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.
 
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
 
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 ProcessStartInfo

Static myProcess As New Process

StartInfo.FileName = "cmd"

StartInfo.RedirectStandardInput = True

StartInfo.RedirectStandardOutput = True

StartInfo.CreateNoWindow = True

StartInfo.UseShellExecute = False

myProcess.StartInfo = StartInfo

myProcess.Start()

Dim SWIn As System.IO.StreamWriter = myProcess.StandardInput

SWIn.WriteLine(ControlTextEditorIn.Text)

SWIn.WriteLine("exit")

Dim SROut As System.IO.StreamReader = myProcess.StandardOutput

With OpenFileDialog1

...snip..

Dim SWOut As New System.IO.StreamWriter(.FileName)

SWOut.WriteLine(SROut.ReadToEnd)

myProcess.WaitForExit()

SWOut.Close()

Registry.SetValue(mSubKey, "Executed File", .FileName)

End If

End With

SWIn.Close()

SROut.Close()
 
Back
Top