Struggling to get a command to run under .NET core but no luck.
I have a basic command like below I would like to execute:
mysqldump -h ... -u ... -p... -P 3306 name > backup_020423_153050.sql
I have written a C# class to do this for me:
public static void RunShellCommand(string command, string arguments)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
},
};
process.Start();
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(output))
{
Console.WriteLine(output);
}
if (!string.IsNullOrEmpty(error))
{
Console.WriteLine(error);
}
}
Calling it like so:
TerminalUtilities.RunShellCommand(command, $"-h {host} -u {username} -p{password} -P {port} {databaseName} > {fileName}");
Although I get
mysqldump: Couldn't find table: ">"
What is going on here? My guess is C# is doing something weird with the input.