c# - Output not proper when calling batch file programatically -


i trying automate server patch installation product , came know wix toolset. hoping jboss version in installer. command same standalone.bat --version cmd. installer created 1 customaction tried run , output.

public static string runrunnablebatch(string path){     process exploitversionservice = new process();     string runnablebinpath = path;     exploitversionservice.startinfo.workingdirectory = path + "bin";     exploitversionservice.startinfo.filename = path + "bin\\standalone.bat";     exploitversionservice.startinfo.createnowindow = false;     exploitversionservice.startinfo.arguments = string.format("--version");     exploitversionservice.startinfo.useshellexecute = false;     exploitversionservice.startinfo.redirectstandardoutput = true;     exploitversionservice.startinfo.redirectstandardinput = false;     exploitversionservice.start();     exploitversionservice.waitforexit();     // /*     string opt = "";     while (!exploitversionservice.standardoutput.endofstream){         opt += exploitversionservice.standardoutput.readline();     }     // */     //using (streamwriter writer = new streamwriter("d:\\_log.txt"))     //using (streamreader reader = exploitversionservice.standardoutput){     //    writer.autoflush = true;     //    (; ; ){     //        string textline = reader.readline();     //        if (textline == null)     //            break;     //        writer.writeline(textline);     //    }     //}     //streamreader exploitversionfeed = exploitversionservice.standardoutput;     //string output = exploitversionfeed.readtoend();     return opt; } 

when doing that, got output first line of whole output string.

i needed whole string in code regular expression extract version.

also tried with

public static string runrunnablebatch(string path){     string executablebinpath = path + "bin";     string executablebinpath_batchcmd = "cd " + "\"" + executablebinpath + "\"";     string outputfilename = "tempverinfoholder.txt";     string outputfilepath = executablebinpath+@"\tempverinfoholder1.txt";     string versionretriever_batchcmd = @"standalone.bat --version > " + "\""+outputfilepath+"\"";     string partitionname_batchcmd = @strings.utils.getpartitionfrompath(path);      // creating command sequence     sortedlist<int, string> commandsequence = new sortedlist<int, string>();      // ~ d:     commandsequence.add(1, partitionname_batchcmd);     // ~ cd %path%     commandsequence.add(2, executablebinpath_batchcmd);     // ~ standalone.bat --version > %filename%     commandsequence.add(3, versionretriever_batchcmd);     runcommandfromsequence(commandsequence);      // run      return ""; }  private static void runcommandfromsequence(sortedlist<int, string> commandsequence){     process seqcmdexechost = new process();      processstartinfo psi = new processstartinfo();     psi.filename = "cmd.exe";     psi.redirectstandardinput = true;     psi.redirectstandardoutput = true;     psi.useshellexecute = false;     psi.createnowindow = false;      seqcmdexechost.startinfo = psi;     seqcmdexechost.start();      using (streamwriter writer = seqcmdexechost.standardinput) {         if (writer.basestream.canwrite) {             foreach (int item in commandsequence.keys){                 messagebox.show(seqcmdexechost.id.tostring());                 messagebox.show(commandsequence[item]);                 writer.writeline(commandsequence[item]);                }         }          string opt = "";         while (!seqcmdexechost.standardoutput.endofstream){             opt += seqcmdexechost.standardoutput.readline();         }     messagebox.show("exited? " + seqcmdexechost.hasexited);     messagebox.show("o/p? " + opt);     } } 

i have tried other way well. switching commented code of above function 1 of them.

output getting while doing code level

calling "d:\servers\va\xyz\jboss-7.1.1-final\bin\standalone.conf.bat

output while running same command manually cmd

calling d:\servers\va\xyz\jboss-7.1.1-final\bin\standalone.conf.bat

====================================================================== jboss bootstrap environment

jboss_home: d:\servers\va\xyz\jboss-7.1.1-final

java: c:\program files\java\jdk1.7.0_67\bin\java

java_opts

====================================================================== listening transport dt_socket @ address: 8787

19:08:08,333 info [org.jboss.modules] jboss modules version 1.1.1.ga

jboss 7.1.1.final "brontes"

press key continue . . .

my observation is, stream getting closed once nested standalone.conf.bat getting called standalone.bat.

if workaround available full output in string/buffer/stream, appreciated.

thanks

what call command line application instead of calling batch file

exploitversionservice.startinfo.workingdirectory = path + "bin"; exploitversionservice.startinfo.filename = "cmd.exe"; exploitversionservice.startinfo.createnowindow = false; exploitversionservice.startinfo.arguments = string.format(" /c \"{0}\" --version",path + "bin\\standalone.bat"); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -