handling an executable file in Visual Studio C#
My env is Visual Studio 2008 C# and .Net. I like to call an exec开发者_开发百科utable from the code and pass parameters to it and then get the output. How do I do this?
Thanks Bruce
Use Process.Start
to start a process. How you give it data and get the output will depend on the executable, but you can pass command line arguments, and if it writes its output to a file, that will be simple. You can capture its standard output, standard error and standard input streams too - ideally use ProcessStartInfo
to configure everything you need before starting the process.
Reading/writng data from the process via the standard output/error/input can be slightly tricky (as you may need to use multiple threads) so if you can specify command line arguments to specify input and output files, that would be ideal.
processInfo.FileName =FileName.exe;
processInfo.WorkingDirectory = fileDirectory;
processInfo.RedirectStandardInput =false;
processInfo.CreateNoWindow =true;
processInfo.UseShellExecute =false;
Process startRestore = Process.Start(processInfo);
startRestore.WaitForExit();
Replace your file with "FileName.exe" and File path with fileDirectory. I hope it will be helpful to you.
精彩评论