|
-
Dec 11th, 2002, 01:08 AM
#1
Thread Starter
Member
input / output to a shell
Hi all
There's probably a simple somlution that i'm overlooking here....but....i've got an application running through the Process method. Now i need to sent info to this application, however the data that i send is determined by the output of the application.
e.g. at the command line
>consult.exe -f CommonWords
C4.5 [release 5] decision tree interpreter Wed Dec 11 15:57:33 2002
------------------------------------------
teachers:
the application consult.exe waits for an input after teachers: . Now depending on processing in my c# app a value needs to be entered here(an int) and it should produce
teachers: 0
font:
where the app waits for another input. There are up to 1000 of these. I say up to because at any time the app can stop asking for input (because it has reached a decision (this app classifies a list of words into a topic))
teachers: 0
font: 1
microsoft: 1
Decision:
Science CF = 0.00 [ 0.00 - 1.00 ]
Retry, new case or quit [r,n,q]:
what i want to happen is when it reaches the Science line, c# will record the desicion (science) and send q(for quit obviously).
Because the amount of inputs changes i can't create a batch file to input the values for me. but i'm getting nothing through using StandardOutput from the Process.
My code is
Process classifier = new Process();
classifier.StartInfo.UseShellExecute = false;
classifier.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + "classificationFiles\\consult.exe";
classifier.StartInfo.Arguments = "-f " + System.AppDomain.CurrentDomain.BaseDirectory + "classificationFiles\\CommonWords";
//classifier.StartInfo.CreateNoWindow = true;
classifier.StartInfo.RedirectStandardOutput = true;
classifier.StartInfo.RedirectStandardInput = true;
classifier.Start();
StreamReader sr = classifier.StandardOutput;
sw = classifier.StandardInput;
string line = sr.ReadLine();
Console.WriteLine(line);
while (line != "------------------------------------------")
...... blah blah blah
This code halts at the bolded line "string line = sr.ReadLine();"
Can someone explain how i can overcome this?
J
-
Dec 11th, 2002, 01:50 PM
#2
Hyperactive Member
MessageQueue
Take a look at the MessageQueue component.
With this, you can create, listen to and send message to a message queue. This provides very simple communication between apps.
-scott
he he he
-
Dec 11th, 2002, 03:53 PM
#3
You would usually pass a pipe to Process as the output handle of the new process. You can then read from the pipeline everything the process outputs.
But I don't know how to create pipes in .NET. In API you'd call the CreatePipe function, in .NET it must be some strange argument to the FileStream constructor.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 11th, 2002, 03:59 PM
#4
But actually it should internally create the pipe...
I think the reason is that your code uses ReadLine, which reads up to a newline. But the process you create doesn't output a newline but instead waits for the user to write his input on the same line.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 11th, 2002, 09:03 PM
#5
Frenzied Member
I posted a sample program about something similar a while back. What is does was start a process from the command prompt, grab the output and display it in a windows form. Do a search in the .net forums to find it.
Dont gain the world and lose your soul
-
Dec 12th, 2002, 12:02 AM
#6
Thread Starter
Member
Thanks for the replies....
Scott....i had no idea about message queues but i'll look into them. do you know of any tutes that can help me with these and processes?
Corned....It's strange....the readline works if i just start cmd.exe..it brings up
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
which are the first 2 lines of cmd.....but it doesn't bring up the
C:\>
prob because as you say, it is waiting for a prompt. Do you know any way around this? should i use readblock or something?
Dev...which .net forums? i'm on a few. If it's on these ones could you help me with a name or something to search for?
Thanks for the help and sorry for the trouble
J
-
Dec 12th, 2002, 08:13 AM
#7
Frenzied Member
Dont gain the world and lose your soul
-
Dec 12th, 2002, 10:22 AM
#8
You could use Read to read character per character.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 12th, 2002, 08:30 PM
#9
Thread Starter
Member
dev - thanks man.....looking now
bee - yeah that's going to be my last resort....i don't think that'll be so good in terms of efficiency
thanks all the same though
Cheers
J
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|