相关疑难解决方法(0)

反斜杠并在命令行参数中引用

以下行为是C#.NET中的某些功能还是错误?

测试应用:

using System;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Arguments:");
            foreach (string arg in args)
            {
                Console.WriteLine(arg);
            }

            Console.WriteLine();
            Console.WriteLine("Command Line:");
            var clArgs = Environment.CommandLine.Split(' ');
            foreach (string arg in clArgs.Skip(clArgs.Length - args.Length))
            {
                Console.WriteLine(arg);
            }

            Console.ReadKey();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用命令行参数运行它:

a "b" "\\x\\" "\x\"
Run Code Online (Sandbox Code Playgroud)

在我收到的结果中:

Arguments:
a
b
\\x\
\x"

Command Line:
a
"b"
"\\x\\"
"\x\"
Run Code Online (Sandbox Code Playgroud)

传递给方法Main()的args中缺少反斜杠和未删除的引号.除手动解析外,正确的解决方法是什么Environment.CommandLine

.net c#

20
推荐指数
2
解决办法
2万
查看次数

为什么StartInfo(ProcessStartInfo)总是为空?

根据MSDN:

如果未使用Start方法启动进程,则StartInfo属性不会反映用于启动进程的参数.例如,如果使用GetProcesses获取计算机上运行的进程数组,则每个进程StartInfo属性不包含用于启动进程的原始文件名或参数.

好的,这很有道理.我的问题是,即使你使用Process.Start(),为什么这些参数都是空白的?

例如:

    Dim startInfo As New ProcessStartInfo("firefox.exe")
    startInfo.Arguments = "www.stackoverflow.com"
    startInfo.WindowStyle = ProcessWindowStyle.Minimized
    Process.Start(startInfo)
    For Each proc As Process In Process.GetProcessesByName("firefox")
        Debug.Print(String.Format("ProcessID={0}; Arguments={1}", _
        proc.Id, proc.StartInfo.Arguments))
    Next proc
Run Code Online (Sandbox Code Playgroud)

在这种情况下,即使我提供了Arguments,该属性仍为空:

替代文字http://www.sg-squared.com/images/startinfo.png

是什么赋予了?

.net process

7
推荐指数
1
解决办法
3906
查看次数

标签 统计

.net ×2

c# ×1

process ×1