Controlling a command line program from a GUI

  • Thread starter Thread starter Tuang
  • Start date Start date
T

Tuang

I'd like to create my own mini "IDE" for working with several
programming languages that provide interactive "toplevel" command line
interpreters, such as Python, Ruby, Lisp, Scheme, OCaml, etc. (For
those who haven't played with them, these languages -- unlike C, Java,
C#, or Perl -- are designed to let you carry on an interactive
conversation with them, so you can run each function in your app
independently and interactively from a command prompt.) Several of
these languages have sort of clunky, half-built, 3rd party GUI front
ends for their interpreters, but nothing that I like lets me work in
all of those languages.

I imagine I'll have a multipane C# "Form" containing a tabbed window
for source code, another window pane that is essentially a command
line terminal running the language interpreter that I can interact
with directly, and some buttons/menu items that issue commands to the
Lisp, Python, etc., interpreter: a GUI front end that works for a
variety of interpreters.

What I don't have any idea how to do is to create the terminal window
part and have it act as a command line for an interpreter, nor do I
know how to send the interpreter commands from both the terminal pane
and in response to GUI events (buttons, menus, etc.). Of course I may
need to customize it to some extent for each interpreter I want to
use, but some of it must be generic, too. After all, a "DOS window" is
a GUI app that can provide the I/O for all of these interpreters
without any customization of the DOS window. What I imagine is that
the commands I send are custom, but the way a GUI app works as a front
end to an interactive command line app is generic, and that's what I
don't know how to do.

Any advice, pointers, code snippets, etc. would be appreciated.

Thanks.
 
Check out the Process class. Redirect the StandardOutput and StandardInput
(and probably StandardError as well). It should be quite easy so long as the
CLI you are running was written properly.
 
Hi Tuang,

Thanks for posting in this group.
Just as Matt said, you can manipulate the standardinput and standardoutput
from Process.StandardIutput and Process.StandardOutput property.
Before you use these 2 properties, you must have specified true for the
StartInfo property's RedirectStandardIutput, RedirectStandardOutput
property.
While UseShellExecute on the StartInfo property must be false if you want
to set StandardOutput to true.
Or exception will generate.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top