3テラバイト

プログラム関連備忘録サイト。主にゲーム。

PowerShell Unity

UnityでPowerShellの実行結果を取得する

投稿日:

以下の例ではGet-ChildItemコマンドレットを引数なしで実行、標準出力への出力をDebug.LogでUnityコンソールに出力しています。

System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo()
{
    FileName = "powershell.exe",
    Arguments = "Get-ChildItem",
    CreateNoWindow = true,
    UseShellExecute = false,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    StandardOutputEncoding = System.Text.Encoding.GetEncoding(932),
};

System.Diagnostics.Process process = System.Diagnostics.Process.Start(processStartInfo);
string standardOutput = process.StandardOutput.ReadToEnd();
string standardError = process.StandardError.ReadToEnd();
int exitCode = process.ExitCode;
process.Close();

Debug.Log(standardOutput);

-PowerShell, Unity


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


reCaptcha の認証期間が終了しました。ページを再読み込みしてください。

関連記事

no image

Unity – プラットフォームやエディタ等の実行環境ごとに処理を切り分ける方法

こんにちは、今日はUnityでWindows、Mac、Android、iOS等の各プラットフォームごとや、エディタ上で実行されている場合にスクリプトの処理を切り分ける方法についてまとめていきます。 確 …

no image

PowerShellでアイテムを削除するコマンドレットRemove-Itemの使い方

こんにちは、今日はPowerShellでアイテムを削除するコマンドレットRemove-Itemの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 Remov …

no image

Unity – キー入力を取得する方法まとめ

こんにちは、今日はUnityでキー入力を取得する方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 キー入力の取得 https://docs.unity3d.com/ja/c …

no image

PowerShellでコンソールからの入力を受け取るRead-Hostコマンドレットの使い方

コンソールから入力を受け取る 以下のスクリプトで、プロンプトにRead-Hostに渡した引数の文字列が表示され、入力された値が$inputに格納されます。 $input= Read-Host &quo …

no image

PowerShellでWindows Management Instrumentation (WMI)オブジェクトを取得するコマンドレットGet-WmiObjectの使い方

こんにちは、今日はPowerShellでWindows Management Instrumentation (WMI)オブジェクトを取得するコマンドレットGet-WmiObjectの使い方についてま …