The value coming into this function is: "C:\Export\SFTPPutProd.cmd" "C:\Export\*.csv"
SFTPPutProd.cmd
contains one line of code for testing purposes. This executes fine as long as the argument (and command file) doesn't contain double quotes.
copy %1 C:\Export\copy_destination
How can I get it to run? I've tried using the @ symbol to make it work per other Answers here but no luck. Without the double quotes the command runs fine but I need to support the double quotes in case the folder has spaces.
private string RunCmdAndWait(string command) {
string result;
try {
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
using (Process process = new Process()) {
process.StartInfo = procStartInfo;
process.Start();
// Wait until process does its work
process.WaitForExit();
// Then read the result
result = process.StandardOutput.ReadToEnd();
}
}
catch (Exception ex) {
_log.WriteWarning($"There was an error running the command file {command}");
result = "Error";
}
return result;
}