命令调用C#程序, 路径参数解析错误

来源:互联网 发布:知乎日报 瞎扯合集 编辑:程序博客网 时间:2024/05/16 18:01

开发环境VS2010

 

WinXP命令行运行C#程序
命令行如下:
WindowsFormsApplication1.exe "c:\ " "c:\"
C#代码如下:
 static void Main(string[] args)
        {
            System.Windows.Forms.MessageBox.Show("参数数量" + args.Length);
            for (int i = 0; i < args.Length; i++)
                System.Windows.Forms.MessageBox.Show(args[i]);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
运行结果如下:
---------------------------

---------------------------
参数数量2
---------------------------
确定  
---------------------------
---------------------------

---------------------------
c:\
---------------------------
确定  
---------------------------
---------------------------

---------------------------
c:"
---------------------------
确定  
---------------------------

可能原因C#把\"当成了转义字符解析成"

 

 

在WinXP上,实验了 文件名和目录名都可以有空格,但末尾的空格会自动忽略掉。

0 0
原创粉丝点击