[Tip] always quote the CommandLine arguments that can possibly contain whitespaces

Source: Internet
Author: User

I recently met a issue that: when starting our app by command line way (passing several arguments to the app), on win7, the specified file can always be opened after lanuching our app, while on XP, the file is always not able to be opened! The final reason is that: for arguments that contain whilespaces, when starting a process with it passed in, on XP, it will split it by whilespaces so no valid file can be found so that file won't be opened; while on win7, it can always be treated as one argument. whatever, to mark a argument explicitly, always quote it. see below sample code.

 

Void main (string [] ARGs)

{
String file = "C :\\ Program Files \ Autodesk \ AutoCAD 2010 \ acad.exe ";
String name = "C: \ Documents and Settings \ taox \ Local Settings \ temp \ _ solid_temp.dwg ";
File = "\" "+ file + "\"";
Console. writeline (name );
String strinfo = Name + "/FI/nologo/extapp: leleapplication1 ";
Processstartinfo startinfo = new processstartinfo (file, strinfo );
Process pp = process. Start (startinfo );
Pp. waitforexit ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.