c# - How to set input and capture output for one process? -
i'm writing small console app comunicate chess engine. i'm setting process class , can set input, can not capture output. starting parameters startinfo.redirectstandardinput = true; startinfo.redirectstandardoutput = false;
input possible. when i'm setting startinfo.redirectstandardoutput = true;
empty console window starting, no input possible. saw topic catch console input-output , it's marked accepted not working me.
for program (how here can read last line of output):
var position = file.readalltext("c:\\pos.txt"); processstartinfo startinfo = new processstartinfo(); startinfo.redirectstandardinput = true; startinfo.redirectstandardoutput = false; startinfo.useshellexecute = false; startinfo.errordialog = false; startinfo.filename = "c:\\engine.exe"; process process = new process(); process.startinfo = startinfo; process.start(); process.standardinput.writeline("position startpos moves " + position); process.standardinput.writeline("go"); system.threading.thread.sleep(500); process.standardinput.writeline("stop");
i,ve answered in previous question. add these lines after process.standardinput.writeline("stop");
string lastline = null; while (!process.standardoutput.endofstream) { lastline = process.standardoutput.readline(); } //do want here lastline;
Comments
Post a Comment