Simplest way to get an interactive console for my app

I want a simple, interactive way to demo middle-tier features of my app which have not had a UI created yet. I want an interactive console.

When my application (WPF but it shouldn't matter) boots up I would like to also start a console window. This window should run powershell (or ruby, or python, but preferably powershell) and have its scope set to access my ServiceLocator.

Alternately, I could start up my app and attach to the process appdomain from an external powershell window and grab a reference to the ServiceLocator. Is this even possible?

Anyways, I've created IronRuby engines and set variables in scopes before but if I went that route I would need to essentially create my own console input/display mechanism.

Does anyone know of a better way to go about this?


You could use the ConsoleShell of PowerShell. Something like:

using System.Management.Automation;
using System.Management.Automation.Runspaces;
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
ConsoleShell.Start(runspaceConfiguration, Console.Title, Console.Title, new string[] { });

This would start PowerShell within your process, and you could access your variables, add cmdlets that interact with your app etc'. The ConsoleShell gives you the input/output mechanism, including tab completion and other features of the command line interface.

Any Windows application can create a console by calling the Windows AllocConsole API function. Unfortunately, the .NET Console class doesn't expose that functionality. A few years back, I wrote a series of articles and some code to extend the .NET Console interface and included AllocConsole support. Unfortunately, DevSource seems to have lost the first article in that series.

Here are the two functions you'll want:

[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool AllocConsole();

[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool FreeConsole();

You can download the full extended console support package from my Web site:

I've grown rather fond of Visual Studio's Immediate window where I can simply type assignments or call functions while debugging. It's obviously not what you're looking for, but if you or other readers aren't aware of it, it certainly is very useful.

Take a look at this article: PowerShellTunnel - Script your App from PowerShell at Runtime

The June 20 episode of the CodeCast podcast featured an interview with Jimmy Schementi of the Iron Python team, and he talked about an IronPython Interactive DLR Console in Silverlight. Here's the demo site:

Need Your Help

Administrative Limit Exceeded During C# LDAP Search

c# exception active-directory ldap directoryentry

I am trying to do a LDAP Search however I keep getting the following error:

JDBC Call to Oracle Stored Procedure with parameters of type PL SQL table

java oracle jdbc plsql cursor

I need to make JDBC call to a procedure with parameters of type PL/SQL table.