I am trying to execute 'move' command, how you would in the command prompt, but it fails using Process.Start(). I understand move seems to be some integrated part of cmd and not an isolated executable, is there any way to trigger it using Process anyway ? I need to move some special location folder and trying to use elevated process instead of Directory.Move.
1 Answer
That should work. The arguments should start with '/C' otherwise won't work.
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = @"/C move ""test.txt"" ""test/test.txt""",
UseShellExecute = false
}
};
process.Start();
1 Comment
canton7
(Just as a note: the default for
UseShellExecute changed from true to false with the introduction of .NET Core. Annoyingly, therefore, portable code which runs on both Framework and Core needs to always explicitly set it, as this answer does)
cmd /C <stuff>? I.e. invokecmd.exe, and tell it to run itsmovecommandcmdto do similar things in the past