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();
            }
  • 相关阅读:
    mysql基于Altas读写分离并实现高可用
    mysql基于GTIDS复制
    mysql创建用户账号出错
    mysql存储引擎
    mysql读写分离
    for each ;for in;for of 三者的区别
    关于编程的历史
    用indexof来统计字符出现的次数
    正则表达式
    DOM,BOM
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1848567.html
Copyright © 2011-2022 走看看