How do I execute command line arguments with parameters in C #?

I am trying to compare two folders using the third party UltraCompare comparison tool. The next line calls the program and opens two files ... but it does nothing but open them, and it also doesn't work as expected for folders.

Process.Start("C:\\Program Files\\IDM Computer Solutions\\UltraCompare\\uc.exe", 
textBoxContents1 + " " + textBoxContents2);

      

I would like to use the following command line call, which opens two folders, compares against them, and saves the results in the output.txt file: uc -d -dmf "c: \ dir1" "c: \ dir2" -o "c: \ output.txt "

Also, I will need to use variables for folders instead of hardcoding paths.

How can I work with this code in C #?

UPDATE 1:

I have modified my code as per your suggestions:

var p = new System.Diagnostics.Process();
p.StartInfo.FileName = "C:\\Program Files\\IDM Computer Solutions\\UltraCompare\\uc.exe";
p.StartInfo.Arguments = String.Format("-d -dmf \"{0}\" \"{1}\" -o c:\\output2.txt",
textBoxContents1, textBoxContents2);
p.Start();

      

I am wondering why the third line containing the arguments is still not working ...

UPDATE 2:

My mistake. He is working now! Just doesn't display folders in UltraCompare, but it still writes and saves the result. Thanks guys!

+3


source to share


3 answers


you can use

yourProcess.StartInfo.Arguments = " .....";

      



Example

var p = new System.Diagnostics.Process();
p.StartInfo.FileName = "C:\\Program Files\\IDM Computer Solutions\\UltraCompare\\uc.exe";
p.StartInfo.Arguments = String.Format("-d -dmf {0} {1} -o c:\output.txt",textBoxContents1,   textBoxContents2);
p.Start();

      

+6


source


Process.Start(new ProcessStartInfo
{
   FileName = @"C:\Program Files\IDM Computer Solutions\UltraCompare\uc.exe",
   Arguments = String.Format("\"{0}\" \"{1}\"", textBoxContents1, textBoxContents2)
});

      



+5


source


Make sure you use quotation marks for arguments too! If any of textBoxContents1

or textBoxContents2

contains spaces, you're unloaded!

+1


source







All Articles