Call the cmd command in the program to open a file, and the file path with a space, if the path directly to CMD, then CMD will be the path before the space in front of the part as a parameter, the space after the other argument, the command line execution is truncated behind, resulting in a program error, will pop up C : \program is not an internal or external command, and is not an error prompt for a running program or batch file. The workaround is to add double quotes before and after the incoming arguments, as follows:
PrivateStaticvoidResxtores (ArrayList resxpath) {//Resxfile is a folder that is used to store. resx files that need to be convertedstring s =""; Process p =NewProcess (); p.StartInfo.FileName ="Cmd.exe"; P.startinfo.useshellexecute =False; P.startinfo.redirectstandardinput =True; P.startinfo.redirectstandardoutput =True; P.startinfo.createnowindow =False; P.start ();//+ ' + ' + ' + ' can be replaced with ' \ '//P.standardinput.writeline ("%comspec%/k" + ' + ' + ' + ' "+ @" C:\Program Files (x86) \microsoft Sdks\windows\v7.0a\bin "+" "+ ‘"‘);//P.standardinput.writeline ("%comspec%/k" + ' + ' + ' "' + @" C:\Program Files\Microsoft Visual Studio 10.0\vc\vcvarsall.bat " + ' + ' + ' + ' + ' x86 ');//P.standardinput.writeline (@ "CD C:\Program Files\Microsoft Sdks\windows\v6.0a\bin");for (int i =0; i < Resxpath.count; i++) {String Filename =Resxpath[i]. ToString ();//Write the corresponding algorithm to generate the file name;////resgen E:\Filename1.resx e:\ResName1.resources//P.standardinput.writeline ("ResGen" + filename + "" + System.IO.Path.GetFileNameWithoutExtension (filename) + @ ". resx") ; \stringString Resname =path.getfullpath (Filename) +". resx";String str ="\""+@"C:\Program Files\Microsoft Sdks\windows\v6.0a\bin\resgen.exe"+"\"" +""+ Filename +"" +Resname; P.standardinput.writeline (str);//Parameters with spaces should be quoted to handle P.standardinput.writeline ( "" // here to exit two times // exit Visual Studio to Cmd.exe P.standardinput.writeline ( " Exit "); // exit cmd.exe P.standardinput.writeline ( "exit" ); p.WaitForExit (); s = s + P.standardoutput.readtoend (); P.close (); // return s;}
Public Static stringStartcmd (stringcommand) { stringOutput =""; Try{Process cmd=NewProcess (); Cmd. Startinfo.filename=command; Cmd. Startinfo.useshellexecute=false; Cmd. Startinfo.redirectstandardinput=true; Cmd. Startinfo.redirectstandardoutput=true; Cmd. Startinfo.createnowindow=true; Cmd. Startinfo.windowstyle=Processwindowstyle.hidden; Cmd. Start (); Output=cmd. Standardoutput.readtoend (); Console.WriteLine (output); Cmd. WaitForExit (); Cmd. Close (); } Catch(Exception e) {Console.WriteLine (e); } returnoutput; } Public Static stringStartcmd (stringCommandstringargument) { stringOutput =""; Process cmd=NewProcess (); Try{cmd. Startinfo.filename=command; Cmd. Startinfo.arguments=argument; Cmd. Startinfo.useshellexecute=false; Cmd. Startinfo.redirectstandardinput=true; Cmd. Startinfo.redirectstandardoutput=true; Cmd. Startinfo.createnowindow=true; Cmd. Startinfo.windowstyle=Processwindowstyle.hidden; Cmd. Start (); Output=cmd. Standardoutput.readtoend (); Console.WriteLine (output); Cmd. WaitForExit (); Cmd. Close (); } Catch(Exception e) {cmd. Close (); Console.WriteLine (e); } returnoutput; }
C # invokes the command line with a space on the parameter