Re: How to capture "legacy" program output in MSH and redirect them to MshHostUserInterface
- From: "Bruce Payette [MSFT]" <brucepay@xxxxxxxxxxxxx>
- Date: Wed, 22 Mar 2006 16:30:46 -0800
The answer to this is a bit tricky to explain. When we run a native command
(we don't call them legacy) there is special logic that detects whether the
command is redirected in the script or not. If the command is the last
element in the pipeline and neither that pipeline is redirected nor is it
being called from a redirected context, then we don't redirect the output
console handle. We have do this so things like more.com, vim.exe, etc. can
work. They need to use the console handle not a redirected pipeline. So
here's the tricky example
string script = @"
function my-more { $input | more.com }
ls | my-more
"
pipe = ServerRunspace.CreatePipeline();
pipe.Commands.AddScript(script);
pipe.Commands.Add("out-default");
pipe.Commands[0].MergeMyResults(PipelineResultTypes.Error,PipelineResultTypes.Output);
pipe.Invoke();
In this example, the output of more is technically redirected but we check
to see if the output of the script command is the default output pipe. If it
is, then we give the external process the console handle instead of a
Windows pipe handle and everything works. Now if you do sometime like
string script = @"
function my-more { $input | more.com }
$a = ls | my-more
"
Then the calling context is redirected, the external process will receive a
Windows pipe handle instead and it will (hopefully) use non-interactive
behaviour instead. If you try something like this with say vim.exe in msh,
you get:
(CXT: v1) (19) > $a = vim.exe
Vim: Warning: Output is not to a terminal
<user types :q<cr>>
(CXT: v1) (20) >
So this is a limitation in the design of the host and how it works with
native executables. The workaround is to always explicitly redirect native
commands.
Alternatively, if you don't append the out-default cmdlet, then the command
will always be redirected with the objects being returned to the host. Then
the host can render or serialize them. I'll try to put together a sample of
how you might do this and post it.
In the mean time - could someone post a bug about this? We probably need a
RedirectAlways flag on the runspace that will cause legacy applications to
always be redirected.
Thanks.
--
Bruce Payette [MSFT]
Microsoft Command Shell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"TonyDeSweet" <shenzhonghao@xxxxxxxxx> wrote in message
news:1142868975.517118.177750@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am writing a remote Msh host which will redirect all output to
network stream. go to http://mshforfun.blogspot.com/ for details.
I use following code to invoke pipline:
pipe = ServerRunspace.CreatePipeline();
pipe.Commands.AddScript(Input);
pipe.Commands.Add("out-default");
pipe.Commands[0].MergeMyResults(PipelineResultTypes.Error,PipelineResultTypes.Output);
pipe.Invoke();
It works fine for normal msh script. But "legacy" program still write
output directly to Console. For example:
if Input == "ping 127.0.0.1" the out put did not been directed to
MshHostUserInterface.
How to capture "legacy" program output in MSH and redirect them to my
own MshHostUserInterface.
Thanks
.
- References:
- Prev by Date: run a bat file from a telnet session
- Next by Date: Re: Script to change Profile property for user
- Previous by thread: How to capture "legacy" program output in MSH and redirect them to MshHostUserInterface
- Next by thread: How to override "Prompt" method in MshHostUserInterface?
- Index(es):
Relevant Pages
|