与命令行应用程序交互的最佳方式

与命令行应用程序交互的最佳方式

本文介绍了与命令行应用程序交互的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个组件是一个命令行应用程序交互紧密的应用程序。命令行应用程序会询问一系列问题,进行一些计算,然后终止(我需要检测)。从本质上讲,我想结束这一互动的包装类。

I need to write a component for an application that interacts tightly with a command line application. The command line application asks a series of questions, performs some computations, then terminates (which i need to detect). Essentially, i want to wrap up this interaction in a wrapper class.

有没有人取得过类似的?如果是这样,你怎么做呢?你有没有注意到一个模式,或者一些好身材在课堂上使用?干杯!

Has any one achieved similar in the past? If so, how did you go about it? Did you notice a pattern, or maybe some good build in classes to use? Cheers!

推荐答案

您需要重定向输入和输出流,使用进程;这是稍微复杂一些,同时处理,因为你必须要小心,事情并没有迷失在缓冲区(导致死锁)。

You would need to redirect both the input and output streams, using Process; it is slightly trickier handling both, since you need to be careful that things aren't lost in the buffers (causing deadlock).

  • MSDN:Redirecting输入
  • MSDN:Redirecting输出
  • Here's基本替代的例子。
  • MSDN : Redirecting input
  • MSDN : Redirecting output
  • Here's a basic alternative example.

您可能也想看看OutputDataReceived对于基于事件的响应。

You might also want to look at OutputDataReceived for event-based responses.

这篇关于与命令行应用程序交互的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:21