Running cmd.exe with arguments from C #

I have a folder C: \ Temp \, which has two des.exe and input.abcd files. des.exe is used to decrypt input.abcd. below 2 laid out works on the command line

cd C:\Temp\ des.exe XXXX input.abcd output.zip 

why below doesn't work with c #

  string argument1 = "/K cd C:\\Temp\\ "; string argument2 = "des.exe XXXX input.abcd output.zip" ; System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo(); proc.FileName = @"C:\windows\system32\cmd.exe"; proc.Arguments = String.Format("{0} {1}", argument1, argument2); proc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized; System.Diagnostics.Process.Start(proc); 
+4
source share
2 answers

You do not need to run cmd.exe as a process. All you have to do is run "c: \ temp \ des.exe" with the arguments "XXXX input.abcd output.zip".

 System.Diagnostics.Process.Start("c:\temp\des.exe", "XXXX input.abcd output.zip"); 

Be sure to include your arguments as valid full paths if they differ from the temporary directory.

+8
source

The process you want to run is dec.exe, not cmd.exe. Try this, replace {fullPath} with the path to des.exe:

  string argument2 = "XXXX input.abcd output.zip"; System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo(); proc.FileName = @"C:\\Temp\\des.exe"; proc.Arguments = String.Format("{0} {1}", argument2); proc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized; System.Diagnostics.Process.Start(proc); 
0
source

Source: https://habr.com/ru/post/1387223/


All Articles