相关疑难解决方法(0)

文件路径中的空格问题 - C#中的命令行执行

我正在为命令行程序构建一个gui.在txtBoxUrls [TextBox]中,逐行输入文件路径.如果文件路径包含空格,则程序无法正常工作.该计划如下.

string[] urls = txtBoxUrls.Text.ToString().Split(new char[] { '\n', '\r' });

string s1;
string text;
foreach (string s in urls)
{
    if (s.Contains(" "))
    {
        s1 = @"""" + s + @"""";
        text += s1 + " ";
    }
    else
    {
        text += s + " ";
    }
}


System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.CreateNoWindow = true;


proc.StartInfo.FileName = @"wk.exe";


proc.StartInfo.Arguments = text + " " + txtFileName.Text;

proc.StartInfo.UseShellExecute = false;


proc.StartInfo.RedirectStandardOutput = true;


proc.Start();

//Get program output …
Run Code Online (Sandbox Code Playgroud)

c# command-line filepath

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

command-line ×1

filepath ×1