c# process 输入输出

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "format.com";
p.StartInfo.Arguments = " G: /FS:FAT /Q";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;//true表示不显示黑框,false表示显示dos界面
p.StartInfo.UseShellExecute = false; p.EnableRaisingEvents = true; p.Exited += new EventHandler(p_Exited);
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived); p.Start();
p.StandardInput.WriteLine("");
p.StandardInput.WriteLine(""); //开始异步读取输出
p.BeginOutputReadLine();
p.BeginErrorReadLine(); //调用WaitForExit会等待Exited事件完成后再继续往下执行。
p.WaitForExit();
p.Close(); Console.WriteLine("exit"); } void p_OutputDataReceived(Object sender, DataReceivedEventArgs e)
{
//这里是正常的输出
Console.WriteLine(e.Data); } void p_ErrorDataReceived(Object sender, DataReceivedEventArgs e)
{
//这里得到的是错误信息
Console.WriteLine(e.Data); } void p_Exited(Object sender, EventArgs e)
{
Console.WriteLine("finish");
} }
}

c# process 输入输出的更多相关文章
- 【USACO15FEB】审查(黄金)Censoring (Gold)
题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...
- 「USACO15FEB」「LuoguP3121」审查(黄金)Censoring (Gold)(AC自动机
题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...
- 标准输入输出(C++)
输入输出流函数(模板) #include<iostream> #include<iomanip> using namespace std; int main() { cout ...
- 理解 Node.js 里的 process.nextTick()
有很多人对Node.js里process.nextTick()的用法感到不理解,下面我们就来看一下process.nextTick()到底是什么,该如何使用. Node.js是单线程的,除了系统IO之 ...
- Node.js process 模块常用属性和方法
Node.js是常用的Javascript运行环境,本文和大家发分享的主要是Node.js中process 模块的常用属性和方法,希望通过本文的分享,对大家学习Node.js http://www.m ...
- Node.js的process.nextTick(callback)理解
Node.js是单线程的,基于事件循环,非阻塞 IO的.事件循环中使用一个事件队列,在每个时间点上,系统只会处理一个事件,即使电脑有多个CPU核心,也无法同时并行的处理多个事件.因此,node.js适 ...
- The Linux Process Principle,NameSpace, PID、TID、PGID、PPID、SID、TID、TTY
目录 . 引言 . Linux进程 . Linux命名空间 . Linux进程的相关标识 . 进程标识编程示例 . 进程标志在Linux内核中的存储和表现形式 . 后记 0. 引言 在进行Linux主 ...
- nodejs笔记一--模块,全局process对象;
一.os模块可提供操作系统的一些基本信息,它的一些常用方法如下: var os = require("os"); var result = os.platform(); //查看操 ...
- C# Process 类的思考
在这里,我先给自己留个印象 下面我们用C#实现一个调用Dos命令的小程序,让大家对系统进程能有个直观的了解.要使用Process类,首先要引入System.Diagnostic命名空间,然后定义一个新 ...
随机推荐
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
- HTML5入门篇
---- HTML5简介 HTML5 是用于取代1999年所制定的 HTML 4.01 和 XHTML 1.0 标准的 HTML 标准版本,现在仍处于发展阶段,但大部分浏览器已经支持某些 HTML5 ...
- Android_Json实例
概要: 最近由于自己的兴趣,想在Android开发一个自己的App,需要使用服务器,所以交换数据是逃不掉了的,但是学生党没有固定的服务器,因此使用的新浪的SAE,在学习的前期下可以尝试一下,挺不错的一 ...
- Windows下Wamp装不上Memcache扩展
windows下wamp装不上memcache扩展2015.03.20 No Comments 1,243 views用的是WAMP集成包,PHP版本5.5.12http://windows.php. ...
- Github上关于大数据的开源项目、论文等合集
https://github.com/onurakpolat/awesome-bigdata
- php 用户验证的简单示例
发布:thebaby 来源:net [大 中 小] 本文介绍下,在php中,进行用户登录验证的例子,这个是基于WWW-Authenticate登录验证的实例,有需要的朋友参考下吧. 大家是 ...
- 关于window.location不跳转的问题
今天在码代码的时候遇到个问题:html里采用onclick事件来实现window.location = url的跳转,在内嵌元素上又加上了href="javascrit:;"的属性 ...
- WebService 学习总结
一.概念 Web Web应用程序 Web服务( Web Serivce), SOAP, WSDL, UDDI .Net 框架 ASP.net IIS C#, 代理(委托) 二.实践 1.创建WebSe ...
- custom event in javascript and jquery
javascript: // add a eventListener document.addEventListener("abc", function(){alert('this ...
- C# zip/unzip with DotNet framework 4.5
add reference System.IO.Compression.FileSystem public class ZipHelper { public static string UnZip(s ...