473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
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
Nov 21 '05 #1
0 1659

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tommy Lu | last post by:
Hi, wondering if there is a way to interact the shell command with the C# program? For example, if I type c:\>ver it then suppose to return the version of the OS I am currently using... or ...
6
by: Ian Frawley | last post by:
Hello everyone I have written a Windows Service to monitor local and remote Processes/Applications. However I am stuck because if it is installed as a user account I cannot get it to interact...
1
by: Stephan Steiner | last post by:
Hi I'm trying to automate VPN connection establishment and disconnection using the Cisco VPN client. That particular client has an interactive cli interface. I set my program up to launch the...
0
by: pk | last post by:
I'm using SgmlReader (found at http://www.gotdotnet.com/Community/UserSamples/Details.aspx ?SampleGuid=b90fddce-e60d-43f8-a5c4-c3bd760564bc)and I'm trying to make it iterate over (process)...
10
by: Steve | last post by:
I want to make a web application that will run on my home server and would like to be able to have the web application interact with another, winforms application. For example, let's say I wanted...
1
by: Rvo | last post by:
I'm writing an application that should work both as a GUI and a commandline program. When running from commandline I want to give all output to the commandline instead of showing it it an own...
2
by: Christoph Borger | last post by:
Hello! I have wrote a windows service in vb.net. This service monitors the running processes with WMI and the Win32_Process class. Till last month all seems ok. But since the begin of september...
3
by: balakrishnan.dinesh | last post by:
hi frndz, As we know that, we can pass command line agrument for C using "scanf" commands, So as same as that, Is there any way to pass those commandline arguments through php code to C and...
1
by: KakaICE | last post by:
Hi, I am using Visual Studio 2005 The problem is: The parent.exe launches a child.exe executible. In the child.exe process I want to know the commandline with which parent.exe was originally...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.