Console.WriteLine(
PowerShell
.Create()
.AddScript("'Hello from PowerShell'")
.Invoke()[0]
);
Here are IronPython and IronRuby
Python.CreateEngine()
.Execute("print 'Hello from Iro开发者_如何学CnPython'");
Ruby.CreateEngine()
.Execute("puts 'Hello from IronRuby'");
Yes.
Generally speaking, when creating a "real" PowerShell host, you would need to ADD "Out-Default" to every pipeline, and then implement the host API (UI.WriteLine) so that the output would show up somewhere.
But for a simple "hello world" ... getting the output off the .Invoke() is the simplest thing.
I'm still holding out hope that a future release of PowerShell will be based on the DLR and support the same syntax as the Iron* languages do now for simple invoking... but I don't know if even then you'd get automatic output like that (I'm not sure I'd even want it) because that would basically require the current default "ConsoleHost" to be built into the engine (or something).
精彩评论