c# - cmd process won't execute correct command -
i'm working on project "send" command cmd.exe , receive output. command need file path -k , url. have following code (names , values changed):
string path = "c:\users\program.exe" string pathcustom = "\"" + path + "\""; //the path needs in quotation marks process p = new process(); p.startinfo.filename = "cmd.exe"; p.startinfo.useshellexecute = false; string address = "1.2.3" string command = pathcustom + " " + "-k" + " " + "https://username:passwort@serveradress" + address; //serveradress url p.startinfo.arguments = "/c " + command; p.startinfo.redirectstandardoutput = true; p.start(); string returnvalue = p.standardoutput.readtoend();
this code working fine want be, need methode thats similar except address looks different. in code above 1.2.3 int following method address has (including backslashes , quotation marks) \"ab:cd:de\" let's pretend is
string path = "c:\users\program.exe" string pathcustom = "\"" + path + "\""; process p = new process(); p.startinfo.filename = "cmd.exe"; p.startinfo.useshellexecute = false; string address = @"\""ab:cd:de\"""; string command = pathcustom + " " + "-k" + " " + "https://username:passwort@serveradress" + address; p.startinfo.arguments = "/c " + command; p.startinfo.redirectstandardoutput = true; p.start(); string returnvalue = p.standardoutput.readtoend();
when rewrite code cmd stays open, first method ouput want/expect. second, not working, method, sends command cmd , executes it, writes "message" command either written wrong or couldn't found. when take same code (via streamwriter write command cmd textfile) , copy cmd, executes should. basically, doesn't work if execute command via c#. please help
you have wait application exit use p.waitforexit(milliseconds) or check p.hasexited
Comments
Post a Comment