在 Mac OS X 上无法在 C# 的命令行进程中使用 *(星号)

Can't use *(asterisk) in commandline process from C# on Mac OS X

我正在尝试通过 C# 的进程 class 发出命令行命令,但我发现如果我在命令参数中使用 * 它不会 运行 正确。这是一个例子:

ProcessStartInfo processStartInfo = new ProcessStartInfo
{
    FileName = "scp",

    UseShellExecute = false,
    RedirectStandardOutput = true,
    RedirectStandardInput = true,
    RedirectStandardError = true,
    CreateNoWindow = false,
    Arguments = "<Path>/* " + _remotePath,
    WorkingDirectory = _localPath
};

这会产生:

<Path>/*: No such file or directory

如果我删除 * 并像这样输入特定的文件名

Arguments = "<Path>/file.ext " + _remotePath,

命令 运行 成功。

由于担心通配符可能不起作用,我将其更改为仅在 C# 中构建文件列表并将整个字符串传递给命令行。它不如传入'*'方便,但它具有工作的优点:)

    string[] filePaths = Directory.GetFiles(_localPath);
    string fileList = string.Join(" ", filePaths);

    ...

    Arguments = fileList + " " + _remotePath,