c# - Multiple process commands fail to get back any response -


having challenge being able send commands cmd.exe via c# process class.

basically want call r.exe , send several commands stage data before run r functions , pull out result.

but can't result simple 'dir' statemenet :(

process p = new process(); processstartinfo info = new processstartinfo(); info.filename = "cmd.exe"; info.redirectstandardinput = true; info.redirectstandardoutput = true; info.useshellexecute = false; string pathtor = @"c:\program files\r\r-3.3.1\bin";  p.startinfo = info; p.start();  list<string> output = new list<string>(); using (streamwriter sw = p.standardinput) {     if (sw.basestream.canwrite)     {         sw.writeline("cd " + pathtor);         sw.writeline("dir");           while (p.standardoutput.peek() > -1)         {             var peekval = p.standardoutput.peek();             output.add(p.standardoutput.readline());         }     } } foreach (var line in output) {     console.writeline(line); }  p.standardinput.close(); p.standardoutput.close(); p.waitforexit(); p.close();  console.readline(); 

output:

microsoft windows [version 10.0.10586] (c) 2015 microsoft corporation. rights reserved.  c:\users\micah_000\documents\visual studio 2015\projects\rstagingtestapp\rstagingtestapp\bin\debug>cd c:\program files\r\r-3.3.1\bin process tried write nonexistent pipe. process tried write nonexistent pipe. process tried write nonexistent pipe. process tried write nonexistent pipe. process tried write nonexistent pipe. 

i've seen several variations on result, i've never seen kind of response commands :(

a lot of places async reads work best. i've seen persuasive, comprehensive explanations this, haven't been able work me.

this 1 seemed work. might have been setting autoflush true. or reading once @ end.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -