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

read process output and insert input

Hi,

I started a thread regarding this issue, but now i'm facing new problem, so
i'm starting a new thread, hope it's ok...

anyway, using my c# windows application, i'm excuting and exe file (which is
written in c++), this exe excute some batch files, and those batch file
sometimes wait for user's input.
i want to diplay the output of this exe on win32 form (textbox or something)
and ask the user for input when i need it. the problem is, that i read each
line using ReadLine() function, but when it gets to the stage where the
script needs an input, the process is stuck since readline didn't find a new
line or something like that.
i'm looking for a way to read the output till the point that the user should
insert input, and then insert the input. I saw some c++ program that did that
using pipes and other stuff i couldn't understand.
this is my code:

Process p = new Process();
StreamWriter sw;
StreamReader sr;
StreamReader err;
ProcessStartInfo psI = new ProcessStartInfo();
psI.FileName = @"D:\gidi.exe";
psI.Arguments = "hello gidi";
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;
p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
err = p.StandardError;
sw.AutoFlush = true;
while (!sr.EndOfStream && sr.ReadLine())
{
if (this.richTextBox1.Text != "" && richTextBox1.Text.Contains("?"))
sw.WriteLine("y");

sr.ReadLine();

richTextBox1.Text += Environment.NewLine + line;
}

the batch file the gidi.exe excute is:

ECHO "Welcome %1".
SET /P ANSWER="Do you wish to proceed (y/n) [y] ?"
IF "%ANSWER%" == "" GOTO PROCEED
IF "%ANSWER%" == "y" GOTO PROCEED
IF "%ANSWER%" == "Y" GOTO PROCEED

any help will be appreciated,

Thanks,
Gidi.
Mar 27 '08 #1
0 2681

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

Similar topics

29
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
3
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from...
3
by: Bo | last post by:
In my asp.net webservice application, I need to launch a DOS process as authorized users. To impersonate users, I use <impersonation = true> in my webconfig. I can't use Diagnostics.Process.Start,...
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
8
by: kepioo | last post by:
I currently have an xml input file containing lots of data. My objectiv is to write a script that reports in another xml file only the data I am interested in. Doing this is really easy using SAX....
2
by: ShawnD | last post by:
I'm having some issues when trying to read input off of a pipe using a python script. I'm trying to process packet data from tcpdump in real-time, so it's a filter that needs to read data while the...
8
by: dmoore | last post by:
Hi folks, I've seen the following issue come up in multiple posts to this mailing list: I have a python program that spawns a child process with popen or popen2 or popen3 or popen2.popen2...
7
by: capnwhit | last post by:
Hello all, The program below has a bug... The program is supposed to convert a string to a continuous hex dump and back to a string. The output should be as follows: abcd 61626364 abcd
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.