如何清除进程的标准输入? [英] How to clear StandardInput of the process?

查看:82
本文介绍了如何清除进程的标准输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 c# 应用程序中创建了一个进程,可以读取该进程的输出和错误.在执行每个命令之前,我已经使用 Flush() 清除了 StandardInput 缓冲区.但它不起作用.

I have created a process in c# application and can read the outputs and errors of that process. Before executing each command i have cleared the StandardInput buffer by using Flush(). but it is not working.

如何清除进程的StandardInput?

How can i clear the StandardInput of the process?

注意:进程仍在运行,我只是在执行命令.比如执行cmd.exe中的命令.

Note: The process is still running, i'm just executing the commands only. like executing the commands in cmd.exe.

我的代码在这里process.StandardInput.Flush();process.StandardInput.Write(command);

任何帮助将不胜感激.

推荐答案

当您写入标准输入时,为时已晚.Flush 仅用于发送数据(我不确定它是否在标准 I/O 的情况下做任何事情 - 我不希望它),它不会清除任何东西.如果您不想要标准输入中的某些内容,请首先不要发送它.

By the time you've written into Standard Input, it's too late. Flush only serves to send the data forth (and I'm not sure if it even does anything in the case of standard I/O - I don't expect it to), it doesn't clear anything. If you don't want something on standard input, don't send it in the first place.

这篇关于如何清除进程的标准输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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