zoukankan      html  css  js  c++  java
  • [Tip]Always Quote the commandline arguments that can possibly contain whitespaces

    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:ConsoleApplication1";
                ProcessStartInfo startinfo = new ProcessStartInfo(file, strInfo);
                Process pp = Process.Start(startinfo);
                pp.WaitForExit();
            }
  • 相关阅读:
    第一篇随笔
    我的第一篇博客
    第一次博客
    芜湖
    芜湖~
    起飞
    第一天
    第一篇随笔
    第一篇随笔
    随笔
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1848567.html
Copyright © 2011-2022 走看看