Search code examples
c#macoscommand-linescp

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


I'm trying to issue a commandline command via C#'s Process class and I've discovered it won't run correctly if I use an * in the command arguments. Here's an example:

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

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

This produces:

<Path>/*: No such file or directory

If I remove the * and put in an specific filename like so

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

the command runs successfully.


Solution

  • Following the concern that wildcards might not work, I changed it up to just build the file list in C# and pass that whole string to the commandline. It's not as convenient as passing in '*', but it has the advantage of working :)

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