Created
July 10, 2019 13:42
-
-
Save willard1218/2e50949595d937e9a468830712d6e656 to your computer and use it in GitHub Desktop.
dfsdfsd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Management.Automation; | |
using System.Management.Automation.Runspaces; | |
using System.Collections.ObjectModel; | |
namespace TestPowerShell | |
{ | |
class Program | |
{ | |
[STAThread] | |
static void Main(string[] args) | |
{ | |
InitialSessionState state = InitialSessionState.Create(); | |
//state.ApartmentState = System.Threading.ApartmentState.STA; | |
state.LanguageMode = PSLanguageMode.FullLanguage; | |
state.ThreadOptions = PSThreadOptions.UseCurrentThread; | |
PowerShell objPSInstance = PowerShell.Create(state); | |
var cmd01 = "[Windows.Globalization.JapanesePhoneticAnalyzer, Windows.Globalization, ContentType=WindowsRuntime]::GetWords('$t');"; | |
objPSInstance.AddScript(cmd01); | |
objPSInstance.AddParameter("$t", "あの頃、君を追いかけた"); | |
Collection<PSObject> psObjects = objPSInstance.Invoke(); | |
foreach (PSObject output in psObjects) | |
{ | |
if (output != null) | |
{ | |
Console.WriteLine(output.Members["DisplayText"].Value); | |
Console.WriteLine(output.Members["IsPhraseStart"].Value); | |
Console.WriteLine(output.Members["YomiText"].Value); | |
Console.WriteLine(output.BaseObject.ToString()); | |
} | |
} | |
PSDataCollection<ErrorRecord> errors = objPSInstance.Streams.Error; | |
if (errors != null && errors.Count > 0) | |
{ | |
Console.WriteLine("執行過程中發生錯誤\n"); | |
foreach (ErrorRecord err in errors) | |
{ | |
System.Console.WriteLine("錯誤: {0}", err.ToString()); | |
} | |
} | |
Console.WriteLine("done\n"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment