Wednesday, April 24, 2019

Run command from C#





Folks,
I have a simple expression that I am able to run by pasting it in the "search program and files" :



"C:\Program Files (x86)\notepad.exe" /BF: "D:\BatchMerge\DcaBatch.bpf"



If I have use the same expression in the C# code, what should I use? I searched on stackflow and found "Process.startinfo". I tried using it as below:




Process.Start(""C:\Program Files (x86)\notepad.exe" /BF: "D:\BatchMerge\DcaBatch.bpf"");


That does not work!


Answer



You should separate the executable from the arguments. Look at this overload. So you'd do this instead:



Process.Start(@"C:\Program Files (x86)\notepad.exe", "/BF: \"D:\\BatchMerge\\DcaBatch.bpf\"");


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...