I'm having a problem Interacting with Command Line programs. I can read and
write anything I want as long as I don't have to interact with a process
once it's started. Originally I had been calling 'test.bat' directly, and in
the latest incarnation (below) I am starting up cmd.exe and then writing the
commands I want to execute to the command line that way.
My problem is that I need to know if a program is waiting for input. In my
batch file I put a "pause" which normally waits for the user to press enter.
I thought I could read Text until I saw the "Please press enter to continue"
prmpt, but the program stops reading lines at "c:\pause", so it never gets
there.
My actual problem is with a command line vpn client I'm trying to connect
with. After a connection I get a Prompt saying "this is a secured
connection, and that I am only allowed to connect for the intended purpose.
Do I agree? [y]/[n]" At this point I need to send a y to the program.
I figure if I can't get it to work with "Pause", then it's going to be even
more difficult trying to read through a program expecting a real answer...
Start Code
----------------------------------------------------------------------------
----
Dim txt As String
p = New System.Diagnostics.Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.StartInfo.FileName = "cmd.exe"
p.Start()
Dim sIn As IO.StreamWriter
sIn = p.StandardInput
sIn.WriteLine("c:")
sIn.WriteLine("cd \")
sIn.WriteLine("test.bat")
Dim sOut As IO.StreamReader
sOut = p.StandardOutput
Do While sOut.Peek() >= 0
txt = sOut.ReadLine 'Hangs on this line after reading c:\pause the
previous time thorugh the loop
Me.txtLog.Text &= txt
Loop
'I have all of my checks for closing the process in another sub and are
'left out here for brievity.
----------------------------------------------------------------------------
----
End Code
Here is the test.bat file called in the program. I can read the results of
the Dir command, but as soon as I read the c:\pause line. The program
hangs...
Start Batch File
----------------------------------------------------------------------------
----
dir c:\drivers
pause
----------------------------------------------------------------------------
----
End Batch File
I appreciate any suggestions, that anyone may have.
Thanks,
Wayne