c# - CMD result into a DropDownList -


i'm trying create installer restores database , want return results cmd command sqlcmd -l drop down select on button click event.

is there possible way achieve without sending output of command file.txt , read each line afterwards?

private void button1_click(object sender, eventargs e) {     string command;     command = "sqlcmd -l " ;      try     {         system.diagnostics.processstartinfo procstartinfo =         new system.diagnostics.processstartinfo("cmd", "/c " + command);          procstartinfo.redirectstandardoutput = true;         procstartinfo.useshellexecute = false;         procstartinfo.createnowindow = false;          system.diagnostics.process proc = new system.diagnostics.process();         proc.startinfo = procstartinfo;         proc.start();         //get result , populate drop down     }     catch (exception objexception)     {         // log exception     } } 

not sure if need, process class has standardoutput property allows data dumped standard output (usually console) process. after process has finished (use proc.waitforexit() that) can do:

string processoutput = proc.standardoutput.readtoend(); 

then if need process each line separately, can do:

var lines = processoutput.split(     new[] {environment.newline},     stringsplitoptions.removeemptyentries); foreach(var line in lines) { ... } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -