psi.FileName = "cmd.exe";
//psi.Arguments = "";
psi.UseShellExecute = false; // required for stream redirection.
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.CreateNoWindow = false;
return psi;
With cmd.exe it works fine. I get input and output redirected. When I
change cmd.exe to msh.exe, I get the MSH Banner put nothing after that and
no prompt. I figure msh.exe does something with the streams. Any ideas?
--
William Stacey [MVP]
We do have a bug about this (feature?) prompt not being printed but its
relatively low priority right now as we haven't heard from many people about
it. If it affects you in some way we'd really like to hear about it, or
better yet, have a bug on it and have people vote on it.
Thanks
Marcel
--
Marcel Ortiz [MSFT]
Monad: Microsoft Command Shell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"William Stacey [MVP]" <william...@gmail.com> wrote in message
news:ufnStqR...@TK2MSFTNGP12.phx.gbl...
Here is all I get:
Microsoft Command Shell
Copyright (C) 2005 Microsoft Corporation. All rights reserved.
--
William Stacey [MVP]
"Marcel Ortiz [MSFT]" <mos...@microsoft.com> wrote in message
news:eJ28iQSV...@TK2MSFTNGP15.phx.gbl...
I started with console redirection myself which just doesn't do the job.
Next, with hints from Jeffrey and his team, I created a .NET wrapper using
the MSH host directly so I can access all its internal objects. This does
work *sort of*:
Whenever I have MSHHost execute something, it *will* return the results via
its internal "WriteLine" method.
I *am* able to output this to a console no problem.
However, the moment I try to grab this output to process it myself, I run
into problems.
For some reason, MSH seems to be blocked until all output is received. So
when I try to output the results into a textbox control, I don't get any
output until the entire output is created, and I also get a stack overflow
indicating that the incoming data could not be processed in time.
Please please please we are all full of ideas what we could do with MSH.
However, currently it is simply not possible without internal knowledge to
create even a simple wrapper class. Could the MSH team please put such a
thing on the prio list? We all here outside of MS are eager to step in and
support MSH. Please enable us!
Dr. Tobias Weltner
MVP Windows Server / Admin Frameworks
"William Stacey [MVP]" <william...@gmail.com> schrieb im Newsbeitrag
news:OWTtU$SVGHA...@TK2MSFTNGP15.phx.gbl...
--
William Stacey [MVP]
"Tobias Weltner" <tobweltnerAThotmail.com> wrote in message
news:O7rSNEvV...@TK2MSFTNGP15.phx.gbl...
|I would like to expand on this topic. To embrace MSH and build tools and
| editors for it, it is absolutely necessary to create a "wrapper" around
it.
|
| I started with console redirection myself which just doesn't do the job.
| Next, with hints from Jeffrey and his team, I created a .NET wrapper using
| the MSH host directly so I can access all its internal objects. This does
| work *sort of*:
| Whenever I have MSHHost execute something, it *will* return the results
via
| its internal "WriteLine" method.
| I *am* able to output this to a console no problem.
| However, the moment I try to grab this output to process it myself, I run
| into problems.
| For some reason, MSH seems to be blocked until all output is received. So
| when I try to output the results into a textbox control, I don't get any
| output until the entire output is created, and I also get a stack overflow
| indicating that the incoming data could not be processed in time.
...
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "msh.exe";
psi.Arguments = "-command -";
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.CreateNoWindow = false;
Process p = Process.Start(psi);
p.StandardInput.WriteLine("dir");
p.StandardInput.Close();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine("Printing characters...");
Console.WriteLine(output);
Marcel Ortiz [MSFT]
Monad: Microsoft Command Shell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"William Stacey [MVP]" <william...@gmail.com> wrote in message
news:OWTtU$SVGHA...@TK2MSFTNGP15.phx.gbl...
Runspace r = RunspaceFactory.CreateRunspace();
r.Open();
Pipeline p = r.CreatePipeline("while(1) { 1..10 }");
p.Input.Close();
p.InvokeAsync();
do
{
Collection<MshObject> output = p.Output.NonBlockingRead();
foreach (MshObject obj in output)
{
Console.WriteLine(obj.ToString());
}
}
while (p.Output.IsOpen);
--
Marcel Ortiz [MSFT]
Monad: Microsoft Command Shell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Tobias Weltner" <tobweltnerAThotmail.com> wrote in message
news:O7rSNEvV...@TK2MSFTNGP15.phx.gbl...
Here is a couple more questions if you don't mind related to this:
1) How to send up/down arrows to get history back on std out?
2) How to signal cntrl-c to msh.exe via std-in. p.Kill() is not very nice.
3) As the prompt is not sent back on std-out, how to get the curr dir from
msh.
4) How to know when cmd is actually completed via code.
TIA
--
William Stacey [MVP]
"Marcel Ortiz [MSFT]" <mos...@microsoft.com> wrote in message
news:%23X9SCp1...@TK2MSFTNGP09.phx.gbl...
A CR or Q sent down std-in does not seem to work. Any ideas here?
--
William Stacey [MVP]
"William Stacey [MVP]" <william...@gmail.com> wrote in message
news:unMTCZ2V...@TK2MSFTNGP14.phx.gbl...
Rest Inline.
"William Stacey [MVP]" <william...@gmail.com> wrote in message
news:unMTCZ2V...@TK2MSFTNGP14.phx.gbl...
> Thanks Marcel! That did it.
>
> Here is a couple more questions if you don't mind related to this:
> 1) How to send up/down arrows to get history back on std out?
> 2) How to signal cntrl-c to msh.exe via std-in. p.Kill() is not very
> nice.
You can do that using the Native APIs keybd_event and SendMessage. If you
search for keybd_event you'll find that the first hits are libraries for
simulating keyboard input.
> 3) As the prompt is not sent back on std-out, how to get the curr dir from
> msh.
You can execute (get-location).Path
MSH>(get-location).Path
C:\monad
> 4) How to know when cmd is actually completed via code.
Process.WaitForExit() ?
--
William Stacey [MVP]
"Marcel Ortiz [MSFT]" <mos...@microsoft.com> wrote in message
news:OpFX3J3V...@TK2MSFTNGP11.phx.gbl...
In case you are wondering what we all are trying to do: we want to wrap MSH
to provide tools and editors for it.
While MSH really rocks, it is *very* console-centric, and that's a sad
thing. As *the* new scripting platform, it should be independent of any
platform or infrastructure and rather accept input, process it and return
output.
So this is what we are trying to create.
Thanks & best
tob
"Marcel Ortiz [MSFT]" <mos...@microsoft.com> schrieb im Newsbeitrag
news:%23U4G0C2...@TK2MSFTNGP15.phx.gbl...
I'll try it with my other sample where I do a customrunspace-declaration...
"Marcel Ortiz [MSFT]" <mos...@microsoft.com> schrieb im Newsbeitrag
news:%23U4G0C2...@TK2MSFTNGP15.phx.gbl...
public override void SetBufferContents(Rectangle rectangle,
BufferCell fill)
{
//throw new NotImplementedException("The SetBufferContents()
method is not implemented by MyRawUserInterface.");
}
How should you implement SetBufferContents from the c# side using Console?
I have been working on this now for months on and off but never got
anywhere. Yes it is possible to get some info out of MSH. However, all
approaches had so many severe limitations that none so far was even remotely
suitable for controlling the MSH/being a starting point for
tools/editors/etc..
One point may be that the MSH object model is extremely complex and not
really documented. If it *is* easy or even possible at all, why can't the
MSH team post one simple example on how to send multiple subsequent commands
to MSH and have the results returned including ways to provide the "special
key events" like CTRL+C without using a console window - saving all of us a
great deal of frustration ;-)
Another point may be that the console has been integrated into the MSH
design so tightly that it really can't be left out. Which in my opinion
would be a real design problem since MSH is supposed to be the
next-generation script language and not just the next generation console. In
this case, I'd suggest using a hidden console window at the heart of MSH and
provide programmatic support for sending and receiving console data
*including* special key strokes such as CTRL+C...
Anyway, any help and suggestions greatly appreciated! I keep searching and
trying and bashing my head on my desk...
tob
I have tried to write a remote client for MSH.exe
(http://MSHForFun.blogspot.com/) and I have been through all the
troubles to access monad engine using different UI. If you really want
a comlicated UI, implementation of your own Hosting API is the way to
go. It is not possible to just redirect Stdin and Stdout.
But even after you have your own MshHost, MshHostUserInterface and
MshHostRawUserInterface, you can still running into problems. for
example,
1. Legacy program (like ping) instead of using UI and RawUI, write its
output directly to Console.Out. So you still have to redirect Stdin
and Stdout in you MshHost. Things wents even worse when Legacy program
try to read from stdin.
2. The Console.Readkey didnot compatible with Readkey() definition in
MshHostRawUserInterface. So it is very difficult to write a 100%
compatible Readkey().
3. GetBufferContent and SetBufferContent is another pain
So I would like to see improvement of MshHost, MshHostUserInterface
and MshHostRawUserInterface. they should be more generic but not
"Console-centric".
Hope that will help.
Tony
http://MSHForFun.blogspot.com/
using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
using System.Globalization;
using System.Collections.ObjectModel;
namespace Microsoft.Samples.Msh.Host
{
class MshListenerConsoleSample
{
public bool ShouldExit
{
get
{
return shouldExit;
}
set
{
shouldExit = value;
}
}
private bool shouldExit;
public int ExitCode
{
get
{
return exitCode;
}
set
{
exitCode = value;
}
}
private int exitCode;
private MyHost myHost;
private Runspace myRunSpace;
private Pipeline currentPipeline;
/// <summary>
/// Used to serialize access to instance data...
/// </summary>
private object instanceLock = new object();
MshListenerConsoleSample()
{
myHost = new MyHost(this);
myRunSpace = RunspaceFactory.CreateRunspace(myHost);
myRunSpace.Open();
}
void executeHelper(string cmd, object input)
{
// Just ignore empty command lines...
if (String.IsNullOrEmpty(cmd))
return;
// Create the pipeline object and make it available
// to the ctrl-C handle through the currentPipeline instance
// variable
lock (instanceLock)
{
currentPipeline = myRunSpace.CreatePipeline();
}
// Create a pipeline for this execution - place the result in
the currentPipeline
// instance variable so it is available to be stopped.
try
{
currentPipeline.Commands.AddScript(cmd);
// Now add the default outputter to the end of the pipe and
indicate
// that it should handle both output and errors from the
previous
// commands. This will result in the output being written
using the MshHost
// and MshHostUserInterface classes instead of returning
objects to the hosting
// application.
currentPipeline.Commands.Add("out-default");
currentPipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error,
PipelineResultTypes.Output);
// If there was any input specified, pass it in, otherwise
just
// execute the pipeline...
if (input != null)
{
currentPipeline.Invoke(new object[] { input });
}
else
{
currentPipeline.Invoke();
}
}
finally
{
// Dispose of the pipeline line and set it to null, locked
because currentPipeline
// may be accessed by the ctrl-C handler...
lock (instanceLock)
{
currentPipeline.Dispose();
currentPipeline = null;
}
}
}
void Execute(string cmd)
{
try
{
// execute the command with no input...
executeHelper(cmd, null);
}
catch (RuntimeException rte)
{
// An exception occurred that we want to display
// using the display formatter. To do this we run
// a second pipeline passing in the error record.
// The runtime will bind this to the $input variable
// which is why $input is being piped to out-default
executeHelper("$input | out-default", rte.ErrorRecord);
}
}
void HandleControlC(object sender, ConsoleCancelEventArgs e)
{
try
{
lock (instanceLock)
{
if (currentPipeline != null &&
currentPipeline.PipelineStateInfo.State == PipelineState.Running)
currentPipeline.Stop();
}
e.Cancel = true;
}
catch (Exception exception)
{
this.myHost.UI.WriteErrorLine(exception.ToString());
}
}
private string ExecCmd(string cmd)
{
Pipeline p = this.myRunSpace.CreatePipeline(cmd);
p.Input.Close();
StringBuilder sb = new StringBuilder();
Collection<MshObject> output = p.Invoke();
foreach (MshObject obj in output)
{
sb.Append(obj.ToString());
//Console.WriteLine(obj.ToString());
}
p.Output.Close();
return sb.ToString();
//p.InvokeAsync();
//do
//{
// Collection<MshObject> output = p.Output.NonBlockingRead();
// foreach (MshObject obj in output)
// {
// sb.AppendLine(obj.ToString());
// //Console.WriteLine(obj.ToString());
// }
//}
//while (p.Output.IsOpen);
}
private void Run()
{
// Set up the control-C handler.
Console.CancelKeyPress += new
ConsoleCancelEventHandler(HandleControlC);
Console.TreatControlCAsInput = false;
// loop reading commands to execute until ShouldExit is set by
// the user calling "exit".
string pwd = "";
string prompt = "";
while (!ShouldExit)
{
//pwd =
this.myRunSpace.SessionStateProxy.GetVariable("pwd").ToString();
//prompt = string.Format("\nMSH {0}> ",pwd);
prompt = ExecCmd("prompt");
myHost.UI.Write(ConsoleColor.White, ConsoleColor.Black,
prompt);
string cmd = Console.ReadLine();
Execute(cmd);
}
// and exit with the desired exit code that was set by exit
command.
// This is set in the host by the MyHost.SetShouldExit()
implementation.
Environment.Exit(ExitCode);
}
static void Main(string[] args)
{
// Display the welcome message...
Console.Title = "Monad Console Host Sample Application";
ConsoleColor oldFg = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" Monad Console Host Interactive Sample");
Console.WriteLine(" =====================================");
Console.WriteLine("");
Console.WriteLine("This is an example of a simple interactive
console host using the Monad");
Console.WriteLine("engine to interpret commands. Type 'exit' to
exit.");
Console.WriteLine("");
Console.ForegroundColor = oldFg;
// Create the listener and run it - this never returns...
MshListenerConsoleSample listener = new
MshListenerConsoleSample();
listener.Run();
}
}
}
namespace Microsoft.Samples.Msh.Host
{
class MyHost : MshHost
{
public MyHost(MshListenerConsoleSample program)
{
this.program = program;
}
private MshListenerConsoleSample program;
public override CultureInfo CurrentCulture
{
get { return originalCultureInfo; }
}
private CultureInfo originalCultureInfo =
System.Threading.Thread.CurrentThread.CurrentCulture;
public override CultureInfo CurrentUICulture
{
get { return originalUICultureInfo; }
}
private CultureInfo originalUICultureInfo =
System.Threading.Thread.CurrentThread.CurrentUICulture;
public override void EnterNestedPrompt()
{
throw new NotImplementedException("Cannot suspend the shell,
EnterNestedPrompt() method is not implemented by MyHost.");
}
public override void ExitNestedPrompt()
{
throw new NotImplementedException("The ExitNestedPrompt() method
is not implemented by MyHost.");
}
private static Guid instanceId = Guid.NewGuid();
public override Guid InstanceId
{
get { return instanceId; }
}
public override string Name
{
get { return "MySampleConsoleHostImplementation"; }
}
public override void NotifyBeginApplication()
{
return; // Do nothing...
}
public override void NotifyEndApplication()
{
Console.WriteLine("NotifyEndApplication");
return; // Do nothing...
}
public override void SetShouldExit(int exitCode)
{
program.ShouldExit = true;
program.ExitCode = exitCode;
}
public override MshHostUserInterface UI
{
get { return myHostUserInterface; }
}
private MyHostUserInterface myHostUserInterface = new
MyHostUserInterface();
public override Version Version
{
get {return new Version(1,0,0,0); }
}
}
}
namespace Microsoft.Samples.Msh.Host
{
class MyHostUserInterface : MshHostUserInterface
{
public override Dictionary<string, MshObject> Prompt(string caption,
string message,
System.Collections.ObjectModel.Collection<FieldDescription>
descriptions)
{
Write(ConsoleColor.Blue, ConsoleColor.Black, caption + "\n" +
message + " ");
Dictionary<string, MshObject> results = new Dictionary<string,
MshObject>();
foreach (FieldDescription fd in descriptions)
{
string[] label = GetHotkeyAndLabel(fd.Label);
WriteLine(label[1]);
string userData = Console.ReadLine();
if (userData == null)
return null;
results[fd.Name] = MshObject.AsMshObject(userData);
}
return results;
}
public override int PromptForChoice(string caption, string message,
System.Collections.ObjectModel.Collection<ChoiceDescription>
choices, int defaultChoice)
{
// Write the caption and message strings in Blue.
WriteLine(ConsoleColor.Blue, ConsoleColor.Black, caption + "\n"
+ message + "\n");
// Convert the choice collection into something that's a little
easier to work with
// See the BuildHotkeysAndPlainLabels method for details.
Dictionary<string, MshObject> results = new Dictionary<string,
MshObject>();
string[,] promptData = BuildHotkeysAndPlainLabels(choices);
// Format the overall choice prompt string to display...
StringBuilder sb = new StringBuilder();
for (int element=0; element < choices.Count; element++)
{
sb.Append(String.Format("|{0}> {1} ", promptData[0,element],
promptData[1, element]));
}
sb.Append(String.Format("[Default is ({0}]",
promptData[0,defaultChoice]));
// loop reading prompts until a match is made, the default is
chosen or
// the loop is interrupted with ctrl-C.
while (true)
{
WriteLine(ConsoleColor.Cyan, ConsoleColor.Black,
sb.ToString());
string data =
Console.ReadLine().Trim().ToUpper(CultureInfo.CurrentCulture);
// if the choice string was empty, use the default selection
if (data.Length == 0)
return defaultChoice;
// see if the selection matched and return the corresponding
index if it did...
for (int i = 0; i < choices.Count; i++)
{
if (promptData[0, i] == data)
return i;
}
WriteErrorLine("Invalid choice: " + data);
}
}
/// <summary>
/// Parse a string contining a hotkey character.
///
/// Take a string of the form "Yes to &all" and return a
two-dimensional
/// array split out as "A", "Yes to all".
/// </summary>
/// <param name="input">The string to process</param>
/// <returns>A two dimensional array containing the parsed
componenets.</returns>
private static string[] GetHotkeyAndLabel(string input)
{
string[] result = new string[] {String.Empty, String.Empty };
string[] fragments = input.Split('&');
if (fragments.Length == 2)
{
if (fragments[1].Length > 0)
result[0] =
fragments[1][0].ToString().ToUpper(CultureInfo.CurrentCulture);
result[1] = (fragments[0] + fragments[1]).Trim();
}
else
{
result[1] = input;
}
return result;
}
/// <summary>
/// This is a private worker function splits out the accelerator
keys from the menu
/// and builds a two dimentional array with the first access
containing the accelerator
/// and the second containing the label string with the & removed.
/// </summary>
/// <param name="choices">The choice collection to process</param>
/// <returns>A two dimensional array containing the accelerator
characters and the cleaned-up labels</returns>
private static string[,]
BuildHotkeysAndPlainLabels(Collection<ChoiceDescription> choices)
{
// we will allocate the result array
string[,] hotkeysAndPlainLabels = new string[2, choices.Count];
for (int i = 0; i < choices.Count; ++i)
{
string[] hotkeyAndLabel =
GetHotkeyAndLabel(choices[i].Label);
hotkeysAndPlainLabels[0,i] = hotkeyAndLabel[0];
hotkeysAndPlainLabels[1,i] = hotkeyAndLabel[1];
}
return hotkeysAndPlainLabels;
}
public override MshCredential PromptForCredential(string caption,
string message, string userName, string targetName)
{
throw new NotImplementedException("The method
PromptForCredential() is not implemented by MyHost.");
}
public override MshCredential PromptForCredential(string caption,
string message, string userName, string targetName, MshCredentialTypes
allowedCredentialTypes, MshCredentialUIOptions options)
{
throw new NotImplementedException("The method
PromptForCredential() is not implemented by MyHost.");
}
private MyRawUserInterface myRawUi = new MyRawUserInterface();
public override MshHostRawUserInterface RawUI
{
get { return myRawUi; }
}
public override string ReadLine()
{
return Console.ReadLine();
}
public override System.Security.SecureString
ReadLineAsSecureString()
{
throw new NotImplementedException("The method
ReadLineAsSecureString() is not implemented by MyHost.");
}
public override void Write(string value)
{
Console.Write(value); ;
}
public override void Write(ConsoleColor foregroundColor,
ConsoleColor backgroundColor, string value)
{
ConsoleColor oldFg = Console.ForegroundColor;
ConsoleColor oldBg = Console.BackgroundColor;
Console.ForegroundColor = foregroundColor;
Console.BackgroundColor = backgroundColor;
Console.Write(value);
Console.ForegroundColor = oldFg;
Console.BackgroundColor = oldBg;
}
public override void WriteLine(ConsoleColor foregroundColor,
ConsoleColor backgroundColor, string value)
{
ConsoleColor oldFg = Console.ForegroundColor;
ConsoleColor oldBg = Console.BackgroundColor;
Console.ForegroundColor = foregroundColor;
Console.BackgroundColor = backgroundColor;
Console.WriteLine(value);
Console.ForegroundColor = oldFg;
Console.BackgroundColor = oldBg;
}
public override void WriteDebugLine(string message)
{
this.WriteLine(ConsoleColor.DarkYellow, ConsoleColor.Black,
String.Format("DEBUG: {0}", message));
}
public override void WriteErrorLine(string value)
{
this.WriteLine(ConsoleColor.Red, ConsoleColor.Black, value);
}
public override void WriteLine()
{
Console.WriteLine();
}
public override void WriteLine(string value)
{
Console.WriteLine(value);
}
public override void WriteVerboseLine(string message)
{
this.WriteLine(ConsoleColor.Green, ConsoleColor.Black,
String.Format("VERBOSE: {0}", message));
}
public override void WriteWarningLine(string message)
{
this.WriteLine(ConsoleColor.Yellow, ConsoleColor.Black,
String.Format("WARNING: {0}", message));
}
/// <summary>
/// Progress is not implemented by this class. Since it's not
required for the cmdlet
/// to work, it is better to nothing instead of throwing an
exception.
/// </summary>
/// <param name="sourceId">See base class</param>
/// <param name="record">See base class</param>
public override void WriteProgress(long sourceId, ProgressRecord
record)
{
; // Do nothing...
}
}
}
namespace Microsoft.Samples.Msh.Host
{
class MyRawUserInterface : MshHostRawUserInterface
{
public override ConsoleColor BackgroundColor
{
get { return Console.BackgroundColor; }
set { Console.BackgroundColor = value; }
}
public override Size BufferSize
{
get { return new Size(Console.BufferWidth,
Console.BufferHeight); }
set { Console.SetBufferSize(value.Width, value.Height); }
}
public override Coordinates CursorPosition
{
get
{
//throw new NotImplementedException("The CursorPosition
property is not implemented by MyRawUserInterface.");
return new Coordinates(Console.CursorLeft,
Console.CursorTop);
}
set { Console.SetCursorPosition(value.X, value.Y); }
}
public override int CursorSize
{
get { return Console.CursorSize; }
set { Console.CursorSize = value; }
}
public override void FlushInputBuffer()
{
; //Do nothing...
}
public override ConsoleColor ForegroundColor
{
get { return Console.ForegroundColor; }
set { Console.ForegroundColor = value; }
}
public override BufferCell[,] GetBufferContents(Rectangle rectangle)
{
throw new NotImplementedException("The GetBufferContents method
is not implemented by MyRawUserInterface.");
}
public override bool KeyAvailable
{
get { return Console.KeyAvailable; }
}
public override Size MaxPhysicalWindowSize
{
get { return new Size(Console.LargestWindowWidth,
Console.LargestWindowHeight); }
}
public override Size MaxWindowSize
{
get { return new Size(Console.LargestWindowWidth,
Console.LargestWindowHeight); }
}
public override KeyInfo ReadKey(ReadKeyOptions options)
{
ConsoleKeyInfo cki = Console.ReadKey(false);
KeyInfo ki = new KeyInfo();
ki.Character = cki.KeyChar;
return ki;
//throw new NotImplementedException("The ReadKey() method is not
implemented by MyRawUserInterface.");
}
public override void ScrollBufferContents(Rectangle source,
Coordinates destination, Rectangle clip, BufferCell fill)
{
throw new NotImplementedException("The ScrollBufferContents()
method is not implemented by MyRawUserInterface.");
}
public override void SetBufferContents(Coordinates origin,
BufferCell[,] contents)
{
throw new NotImplementedException("The SetBufferContents()
method is not implemented by MyRawUserInterface.");
}
public override void SetBufferContents(Rectangle rectangle,
BufferCell fill)
{
if (rectangle.Top == -1)
{
Console.Clear();
return;
}
Console.ForegroundColor = fill.ForegroundColor;
Console.BackgroundColor = fill.BackgroundColor;
for(int r = rectangle.Top; r <= rectangle.Bottom; r++)
{
for(int c = rectangle.Left; c <= rectangle.Right; c++)
{
// Console.SetCursorPosition(c, r);
// Console.Write(fill.Character);
}
}
//Console.Clear();
//throw new NotImplementedException("The SetBufferContents()
method is not implemented by MyRawUserInterface.");
}
public override Coordinates WindowPosition
{
get { return new Coordinates(Console.WindowLeft,
Console.WindowTop); }
set { Console.SetWindowPosition(value.X, value.Y); }
}
public override Size WindowSize
{
get { return new Size(Console.WindowWidth,
Console.WindowHeight); }
set { Console.SetWindowSize(value.Width, value.Height); }
}
public override string WindowTitle
{
get { return Console.Title; }
set { Console.Title = value; }
}
}
}
--
William Stacey [MVP]
I wonder how MSH is handling that case. Is there a switch or something in
the hosting apis, as I don't see support for that. Any ideas?
greetings /\/\o\/\/
private void ExecuteHelper(string cmd, object input)
--
William Stacey [MVP]
"/\/\o\/\/" <n...@spam.mow> wrote in message
news:OEqUrdBW...@TK2MSFTNGP14.phx.gbl...
--
William Stacey [MVP]
"TonyDeSweet" <shenzh...@gmail.com> wrote in message
news:1144265391.1...@u72g2000cwu.googlegroups.com...
--
William Stacey [MVP]
"William Stacey [MVP]" <william...@gmail.com> wrote in message
news:OQ1jw9OW...@TK2MSFTNGP05.phx.gbl...
string command = "ping localhost";
command = string.Format("$results = . {{ {0} }}; $results", command);
Pipeline p = r.CreatePipeline(command);
This will force redirection because the results are being assigned to a
variable. It does have one large downside and its that because the results
are assigned to a variable and then the results of the variable are output,
you won't get any results until all the execution is complete.
--
Marcel Ortiz [MSFT]
Monad: Microsoft Command Shell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"William Stacey [MVP]" <william...@gmail.com> wrote in message
news:OQ1jw9OW...@TK2MSFTNGP05.phx.gbl...
Or maybe 1 input Q and 1 output Q and everything is a Message and handled
based on Message type.
Console2...Console2...Console2. I guess I have to punt. Cheers Marcel.
--
William Stacey [MVP]
"Marcel Ortiz [MSFT]" <mos...@microsoft.com> wrote in message
news:%23tPWftQ...@TK2MSFTNGP02.phx.gbl...
But, It is still a problem. As William Stacey mentioned, How do you
know in advance
that next user input is a "native executables".
For a non-interactive "native executables" like ping.exe, it is OK if
we just lost some output. What if an interactive "native executables"
want's to read from Console.In and MshHost did not redirect
Console.In, Host would wait "native executables" to exit and freeze for
a long time( until timeout). This will cause big problem.
I did not find a way to provide a redirected stdin so far that would work
with such commands.
I tend to agree that MSH development is a bit too console-centric. After
all, we are all more or less trying to escape the console. I'd love to see
some general "console wrapper".
Does anyone know when there will be a more comprehensive SDK for MSH? I
found some bits but without the meat I was looking for... ;-)
Thanx!
"TonyDeSweet" <shenzh...@gmail.com> schrieb im Newsbeitrag
news:1144420622.7...@u72g2000cwu.googlegroups.com...
--
William Stacey [MVP]
"Tobias Weltner [MVP]" <tobweltnerAThotmail.com> wrote in message
news:uLRPPFLX...@TK2MSFTNGP05.phx.gbl...
--
William Stacey [MVP]
"Tobias Weltner [MVP]" <tobweltnerAThotmail.com> wrote in message
news:%230UyvKL...@TK2MSFTNGP04.phx.gbl...