473,385 Members | 1,453 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,385 software developers and data experts.

launching a commandline program from a c# app

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 VPN client, redirect its
standard input and output, and write to its standard input where a manual
user intervention is required. However, I've come across a problem:
Basically, if I launch the program in a configuration that doesn't require
any manual user interaction, things work just fine and I can read the output
from the redirected stdout until the vpn client exits. However, if user
input is required, when I try to read from the stdout, my program just sits
there doing nothing. But in the background, the vpn client is waiting for
data to be entered (I've tried not redirecting stdout and sure enough the
vpn client is doing its thing, then just sits there waiting for input).

Here's a snippet of my code:

string arguments = "connect " + vpnprofilename + " cliauth";
ProcessStartInfo psi = new ProcessStartInfo(vpnExe, arguments);
psi.RedirectStandardOutput=true;
psi.RedirectStandardInput=true;
psi.UseShellExecute=false;
psi.CreateNoWindow=true;
Process proc = Process.Start(psi); // start the vpnclient
StreamReader reader = proc.StandardOutput;
while ((line = reader.ReadLine())!=null)
{
if (line.IndexOf("Username [") != -1)
{
proc.StandardInput.WriteLine(this.login);
}
if (line.IndexOf("Password [") != -1)
{
proc.StandardInput.WriteLine(this.password);
}
}

If I have no connection error, the vpnclient should eventually write
"Username ["... to the stdout, which I try to catch and upon which I'd then
write the proper password to the stdin. However, I never get to this point.
I never get beyond the while line unless that program runs and exits without
any user intervention (in which case things work as they should but there's
no way to set up a connection fully automatic). Does anybody have any idea
as to how I can capture the stdout of a launched 3rd part cli program if
that one eventually requires some input from stdin (but not right away) and
won't exit until it has received such input?

Regards
Stephan
Nov 16 '05 #1
1 2001
"Stephan Steiner" wrote :
Hi

string arguments = "connect " + vpnprofilename + " cliauth";
ProcessStartInfo psi = new ProcessStartInfo(vpnExe, arguments);
psi.RedirectStandardOutput=true;
psi.RedirectStandardInput=true;
psi.UseShellExecute=false;
psi.CreateNoWindow=true;
Process proc = Process.Start(psi); // start the vpnclient
StreamReader reader = proc.StandardOutput;
while ((line = reader.ReadLine())!=null)


Are you sure that the server send a end of line character ? ReadLine
will wait until that happens. If the server only send "Password: " for
example, the call will wait forever !

Use the Read() method.

--
Francois Beaussier
Fr******@3ie.org.remove
Nov 16 '05 #2

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

Similar topics

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...
7
by: dhussong | last post by:
I have created a Setup and Deployment project in Visual Studio.NET 2003. After my installation has completed running I'd like to launch the EXE that I just installed. I've found how to launch the...
6
by: MS | last post by:
Hi, I have an Gui Application written in C#.net. Is it possible to launch my application from a web application. I also need to pass a parameter to this application so that appropriate data is...
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...
4
by: vol30w60 | last post by:
Hi folks, I am trying to launch a program with PHP code. I am running Apache on Windows XP SP2. I am using the method noted here: http://us2.php.net/manual/en/function.exec.php#59428 To...
1
by: edmondsnake | last post by:
Dear all, I would like to ask questions about my VB.net program. The executable file of the program is called "PSP.exe" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As...
3
by: Ariharan | last post by:
Explain me how to compile and run a C program in commandline(Windows XP Turbo C++ Version 3.0) The program must also accept commandline arguments... Explain with example program to read a number...
8
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'd like to write a program to assist me in upoloading files to my site. I know how to upload the files using C#, I just don't know how to have an interface and still accept commandline parameters. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.