C#通过bash创建symlink没有任何作用

问题描述 投票:0回答:1

我发现这个函数可以通过C#的bash运行任何命令。所以我试着给它传递一个命令来创建一个symlink,但它什么也没做。如果我直接在终端中运行同样的命令,它就会工作。我试着运行其他命令,比如 "ls",结果打印出了正确的项目。为什么symlink命令不工作?

string output = ExecuteBashCommand("ln -s \"/Users/tim/academy-v2/Shared/Client Code\" \"/Users/tim/academy-v2/Shared Assets/Assets/Shared Code/Client Code\"");
UnityEngine.Debug.Log(output); // Prints "" like it worked, but didn't actually do anything.

...

static string ExecuteBashCommand(string command)
{
    command = command.Replace("\"", "\"\"");

    var proc = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = "/bin/bash",
            Arguments = "-c \"" + command + "\"",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true
        }
    };

    proc.Start();
    proc.WaitForExit();

    return proc.StandardOutput.ReadToEnd();
}
c# bash command-line symlink
1个回答
0
投票

用这个替换命令似乎可以,虽然不知道为什么。

"ln -s /Users/tim/academy-v2/Shared/Client\\ Code /Users/tim/academy-v2/Shared\\ Assets/Assets/Shared\\ Code/Client\\ Code"
© www.soinside.com 2019 - 2024. All rights reserved.