So I was successfully able to run a command line application with various arguments from within my project using the following code:
String f = fileName;
Process process = new System.Diagnostics.Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = "C:\\projects\\something\\MediaInfo.exe";
process.StartInfo.Arguments = " \"--Inform=Video;%Duration%|%Width%|%Height%;\" \"" + f + "\"";
process.Start();
StreamReader output = process.StandardOutput;
process.WaitForExit();
MessageBox.Show(output.ReadToEnd());
Now, rather than the absolute path I’ve specified for MediaInfo.exe I’d like to specify a relative path so that when I send my application to someone they won’t need to muck about with placing it in the correct place.
In Visual Studio, I select my project and clicked add existing. I added my files. Then selected “Always Copy.” I’ve tried various items for the “Build Action.” I have a feeling “None” is the correct option.
In any case, my goal is to have process.StartInfo.FileName be a relative path. I don’t know how to do this right. Any ideas?
The root directory of your application can be obtained by…
This statement requires System.IO and System.Diagnostics in order to compile.
You can append to this value to reach a subdirectory, for example “data”, in your application root by…
The application needs to be running in full trust for these to work…