一、C#中利用process类调用外部程序以及执行dos命令

c#中的Process类可方便的调用外部程序,所以可以通过调用cmd.exe程序加入参数 "/c " + 要执行的命令来执行一个dos命令
(/c代表执行参数指定的命令后关闭cmd.exe /k参数则不关闭cmd.exe)

class ExampleOfLegalsoft
{private string RunCmd(string command){//實例一個Process類,啟動一個獨立進程Process p = new Process();//Process類有一個StartInfo屬性,這個是ProcessStartInfo類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:p.StartInfo.FileName = "cmd.exe";           //設定程序名p.StartInfo.Arguments = "/c " + command;    //設定程式執行參數p.StartInfo.UseShellExecute = false;          //關閉Shell的使用p.StartInfo.RedirectStandardInput = true;    //重定向標準輸入p.StartInfo.RedirectStandardOutput = true;  //重定向標準輸出p.StartInfo.RedirectStandardError = true;   //重定向錯誤輸出p.StartInfo.CreateNoWindow = true;             //設置不顯示窗口p.Start();    //啟動//p.StandardInput.WriteLine(command);        //也可以用這種方式輸入要執行的命令//p.StandardInput.WriteLine("exit");         //不過要記得加上Exit要不然下一行程式執行的時候會當機return p.StandardOutput.ReadToEnd();       //從輸出流取得命令執行結果}
}

二、Process.WaitForExit() and Deadlock

Link:http://www.cnblogs.com/kissknife/archive/2009/09/07/1561629.html

三、C# Getting Current Native Thread (操作系统进程线程)

The native OS threads running in the current process are exposed through the Threads property of the Process class. Please note that this is not the same as a managed thread, these are the actual native threads running on the operating system.

In order to get a pointer to the current executing thread, we must use P/Invoke. Here's how we do it:

[DllImport("kernel32.dll")]
publicstaticexternUInt32 GetCurrentThreadId();
 
UInt32 id = GetCurrentThreadId();
ProcessThread thread = Process.GetCurrentProcess().Threads.Cast<processthread>().Where(t => t.Id == id).Single();

C#之Process相关推荐

  1. 使用Java监控工具出现 Can't attach to the process

    问题重现 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ➜ jinfo -flags 3032 Attaching ...

  2. Mr. Process的一生-Linux内核的社会视角 (2)启动

    原文地址: http://www.manio.org/cn/startup-of-linux-view-of-society.html 其实这才应该是这一系列文章的第一节,因为这篇文章讲的是盘古开天地 ...

  3. 【linux】在CentOS7上更改端口号时报错:Job for sshd.service failed because the control process exited with error

    1.问题描述 在在CentOS7上更改端口号时报错: Job for sshd.service failed because the control process exited with error ...

  4. 【Qt】ubuntu14.04.5 qt5.6中使用opencv3.4报错:Using GTK+ 2.x and GTK+ 3 in the same process is not supported

    问题描述 ubuntu14.04.5 qt5.6中使用opencv3.4报错: Using GTK+ 2.x and GTK+ 3 in the same process is not support ...

  5. 守护进程中创建的对象php,在PHP中生成守护进程(Daemon Process)

    前两天看到一篇文章<如何使用PHP编写daemon process>,其中对核心代码却没有细说,我又查了一些资料,还看了一本<理解Unix进程>,才搞明白生成守护进程的时候发生 ...

  6. template.process(root, out)的用法(shiro项目中来的九)

    假如你现在还在为自己的技术担忧,假如你现在想提升自己的工资,假如你想在职场上获得更多的话语权,假如你想顺利的度过35岁这个魔咒,假如你想体验BAT的工作环境,那么现在请我们一起开启提升技术之旅吧,详情 ...

  7. Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException

    异常Log: Error:Execution failed for task ':app:dexDebug'.  > com.android.ide.common.process.Process ...

  8. symfony2 Process 组件的学习笔记

    2019独角兽企业重金招聘Python工程师标准>>> 安装 composer require "symfony/process:2.7.1" ##描述 proc ...

  9. 用计算机的英语造句process,process的用法总结大全

    process的意思 n. 过程,工序,做事方法,工艺流程 vt. 加工,处理,审阅,审核 vi. 列队行进 adj. 经过特殊加工(或处理)的 变形:过去式: processed: 现在分词:pro ...

  10. 关于v$process与v$session中process的理解

    v$session有个process字段,V$PROCESS有个SPID字段,这两个字段是不是一个意思呢?是不是都代表会话的操作系统进程呢? 官方文档上的解释: SPID      VARCHAR2( ...

最新文章

  1. Python生物信息学⑥绘制热图及火山图
  2. Django打造在线教育平台_day_4: 找回密码
  3. 多个反斜杠的消除处理
  4. android 带清除功能的输入框控件
  5. 【百度地图API】自行获取区域经纬度的工具
  6. $\mathfrak {reputation}$
  7. 分治法在排序算法中的应用(JAVA)--快速排序(Lomuto划分、Hoare划分、随机化快排)
  8. Docker上搭载Solr,重新编辑加载文件的相关命令
  9. dotnet new -i Microsoft.Maui.Templates
  10. 拥抱开源,需要跨越哪些鸿沟? ————《Open Life —— 有关开源的哲学》读后感...
  11. 解析几何 | 吕子根 设三平行平面 $\pi_i:\ Ax+By+Cz+D_i=0\,(i=1,2,3),L,M,N$ 依次是平面 $\pi_1,\pi_2,\pi_3$ 上的任意点,求 $\tria
  12. C语言程序设计(第三版)何钦铭著 习题3-3
  13. c语言猜数字课设报告,c语言猜数字课程设计报告.doc
  14. tempo jsnode扩展 3d图形支持。
  15. 神舟笔记本键盘键位互换
  16. 计算机中的数据(原码,反码,补码)
  17. python练习题17
  18. swoole基础教程-1.简介
  19. PTA 海盗分赃 (25分)
  20. python中如何给散点图上面的特定点做标记

热门文章

  1. 小程序苹果手机地图授权问题
  2. 查看app栈顶Activity名称
  3. 使用树结构存储医院楼房结构
  4. 鸿蒙荣耀magic2,赵丽颖晒荣耀Magic2真机 后置三摄值得期待
  5. java内网正则表达,局域网的IP正则表达式
  6. Apollo自动驾驶教程学习笔记-Apollo规划技术详解6-1
  7. 深入理解linux操作系统中的高端内存
  8. 牛逼!一文看尽2020上半年阿里、腾讯、百度入选AI顶会论文
  9. 【CAD二次开发】获取HATCH填充边界
  10. 构建seq2seq模型的常见问题