.net - Send ctrl+c to a cmd.exe process in c# -
I am currently writing a little bit of back up programs myself, I am using standard windows for the interface, And calling CMd.exe as a new process, and then using XCOPY from within this new process. Everything is working, except this last feature, I want to add it, which has the ability to break the operation.
From a basic command prompt, I can do it properly with ctrl + c, but I can try that I can not use this functionality in the vinophy and process approach. I tried to redirect the standard input and used it to send the consolepace keys. In order to send the revolution in the process, I also tried to send 0x03 and "/ x03", in which I read in other forum posts That's hex code for ctrl + c What I am sending is not registered, and kills the user interface by exiting this process, but Exxp working in the background. XE Leaves the Xcopy.exe slashing the file manually, it is making half the copy and is corrupt, not something that uses ctrl + c at the command prompt.
Am I somewhat unknowingly clear? I'm new to C #, so I'll hold my hands and accept that this is going to be the slowest or misunderstanding how this process works with CMD.XA. However, because the process supports standard input redirection, it seems that at least I should ... work. I have laid out the basic outline of my code below, if it helps to identify where I am messing with.
string XCopyArguments = "\" "+ dir.FullName +" \ "\" "+ Destination" "/ D / S / I / E"; Process XCopyProcess = New Process (); ProcessStartInfo XCopyStartInfo = New ProcessTinfo (); XCopyStartInfo.FileName = "CMD.exe"; XCopyStartInfo.RedirectStandardError = True; XCopyStartInfo.RedirectStandardOutput = True; XCopyStartInfo.RedirectStandardInput = True; XCopyStartInfo.UseShellExecute = false; XCopyStartInfo.CreateNoWindow = True; XCopyStartInfo.Arguments = "/ D / c XCOPY" + XCopyArguments; XCopyProcess.EnableRaisingEvents = True; XCopyProcess.StartInfo = XCopyStartInfo; XCopyProcess.Start (); XCopyProcess.WaitForExit (15000); Int ExitCode = XCopyProcess.ExitCode; If (ExitCode> 0 & amp;! XCopyProcess.HasExited) {XCopyProcess.Kill (); } XCopyProcess.Dispose (); Can thank you in advance for any help.
I do not want to be a volunteer, but I think that you better than copying within your program Will be System Using file, directory and other sections in the Io Namespace, it is really simple, and to leave you full control to report progress, cancel operations, etc.
Comments
Post a Comment