468,505 Members | 1,648 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Interact with CommandLine program using Process Class

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

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"

Dim sIn As IO.StreamWriter
sIn = p.StandardInput

sIn.WriteLine("cd \")

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

'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

Start Batch File
dir c:\drivers

End Batch File

I appreciate any suggestions, that anyone may have.
Nov 21 '05 #1
0 1431

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stephan Steiner | last post: by
2 posts views Thread by Christoph Borger | last post: by
3 posts views Thread by balakrishnan.dinesh | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.