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

メールアドレスが公開されることはありません。

関連記事

no image

PowerShell – Invoke-WebRequestコマンドレットの「応答のコンテンツを解析できません。」エラー対処方法

こんにちは、今日はInvoke-WebRequestコマンドレットの「応答のコンテンツを解析できません。」エラーの対処方法についてまとめていきます。 確認環境 PSVersion 5.1.18362. …

no image

PowerShellでコマンドのヘルプを取得するコマンドレットGet-Helpの使い方

こんにちは、今日はPowerShellでコマンドのヘルプを取得するコマンドレットGet-Helpの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 Get- …

no image

PowerShellでアイテムのコンテンツを取得するコマンドレットGet-Contentの使い方

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

no image

PowerShellで右寄せ左寄せする方法

こんにちは、今日はPowerShellで右寄せ左寄せする方法についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 右寄せ "{0,5}" -f 1 …

no image

PowerShellで実行ポリシーを設定するコマンドレットSet-ExecutionPolicyの使い方

こんにちは、今日はPowerShellで実行ポリシーを設定するコマンドレットSet-ExecutionPolicyの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362. …