ProcessStartInfo.UseShellExecute 属性
2016-04-14 17:54
537 查看
获取或设置一个值,该值指示是否使用操作系统外壳程序启动进程。
命名空间:System.Diagnostics
程序集:System(在 system.dll 中)
语法
C#
C++
VB
J#
JScript
备注
将此属性设置为 false 使您能够重定向输入流、输出流和错误流。
使用操作系统外壳程序启动进程时,您能够使用 Process 组件启动任何文档(可以是任何与可执行文件关联的、拥有默认打开操作的注册文件类型),并对该文件执行操作(如打印)。当 UseShellExecute 为 false 时,使用 Process 组件仅能启动可执行文件。
WorkingDirectory 属性的行为在 UseShellExecute 为 true 并当 UseShellExecute 为 false 时是不同的。当 UseShellExecute 为 true时,WorkingDirectory 属性指定可执行文件的位置。如果 WorkingDirectory 是空字符串,则认为当前目录包含可执行文件。
当 UseShellExecute 为 false 时,不使用 WorkingDirectory 属性查找可执行文件。相反,它被已启动的进程使用,并且只在新进程的上下文中有意义。
示例
C#
C++
VB
命名空间:System.Diagnostics
程序集:System(在 system.dll 中)
语法
C#
C++
VB
public bool UseShellExecute { get; set; }
J#
/** @property */ public boolean get_UseShellExecute () /** @property */ public void set_UseShellExecute (boolean value)
JScript
public function get UseShellExecute () : boolean public function set UseShellExecute (value : boolean)
属性值
若要在启动进程时使用外壳程序,则为 true;否则,直接从可执行文件创建进程。默认为 true。备注
将此属性设置为 false 使您能够重定向输入流、输出流和错误流。
注意 |
---|
如果 UserName 属性不为 空引用(在 Visual Basic 中为 Nothing) 或不是一个空字符串,则 UseShellExecute 必须为 false,否则调用Process.Start(ProcessStartInfo) 方法时将引发 InvalidOperationException。 |
注意 |
---|
如果将 ErrorDialog 属性设置为 true,则 UseShellExecute 必须为 true。 |
当 UseShellExecute 为 false 时,不使用 WorkingDirectory 属性查找可执行文件。相反,它被已启动的进程使用,并且只在新进程的上下文中有意义。
示例
C#
C++
VB
Process compiler = new Process(); compiler.StartInfo.FileName = "csc.exe"; compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs"; compiler.StartInfo.UseShellExecute = false; compiler.StartInfo.RedirectStandardOutput = true; compiler.Start(); Console.WriteLine(compiler.StandardOutput.ReadToEnd()); compiler.WaitForExit();
相关文章推荐
- shell 中 &&和||的方法
- shell--条件测试语句和流程控制语句的使用
- Win10支持Ubuntu Linux Bash-apache+php+mysql环境搭建
- bash脚本学习--批量增删用户
- strace在线上环境的troubleshooting
- shell远程执行 远程执行脚本
- shell脚本的基本使用--bash
- Linux学习笔记--yum命令(Shell前端软件包管理器)
- 捉急:ssh vim中不小心按下ctrl+s后卡死
- shell运算
- c语言编写简单shell解释器
- mac shell命令连接mongo
- 进入BIOS SHELL DUMP 命令
- Linux下Bash编程之位置和特殊变量(四)
- shell中if条件字符串、数字比对,[[ ]]和[ ]区别
- python 执行shell
- Xshell 码
- 【Shell】linux中shell变量$#,$@,$0,$1,$2的含义解释 && set 关键字使用
- shell递归下载repo网站文件
- -bash: rz: command not found