本文介绍了从.NET应用程序执行shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从我的.NET应用程序执行shell命令,与。然而用粗略的搜索我找不到任何东西。如何做?
I need to execute a shell command from my .NET application, not unlike os.execute
(a little way down on that page) in Lua. However with a cursory search I couldn't find anything. How do I do it?
推荐答案
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "blah.lua arg1 arg2 arg3";
p.StartInfo.UseShellExecute = true;
p.Start();
另一种方法是使用并直接使用ShellExecute:
Another way would be to use P/Invoke and use ShellExecute directly:
[DllImport("shell32.dll")]
static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
ShowCommands nShowCmd);
这篇关于从.NET应用程序执行shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!