从.NET应用程序中执行shell命令 [英] Execute a shell command from a .NET application

查看:123
本文介绍了从.NET应用程序中执行shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从我的.NET应用程序中执行shell命令,没有什么不同 操作系统.execute (下该页上一点点地)中的 Lua的的。然而,随着一个粗略的搜索,我找不到任何东西。我该怎么做呢?

解决方案

 的System.Diagnostics.Process P =新的System.Diagnostics.Process();
p.StartInfo.FileName =blah.lua ARG1 ARG2 ARG3;
p.StartInfo.UseShellExecute = TRUE;
p.Start();
 

另一种方法是使用的P / Invoke 和使用的ShellExecute直接:

  [的DllImport(SHELL32.DLL)
静态外部的IntPtr的ShellExecute(
    IntPtr的HWND,
    串lpOperation,
    字符串参数lpFile,
    串lpParameters,
    串lpDirectory,
    ShowCommands nShowCmd);
 

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();

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命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆