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でテキストファイルに書き込む

こんにちは、今日はPowerShellでテキストファイルに書き込む方法についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 テキストファイルに書き込む System. …

no image

Unity – コルーチンの使い方

こんにちは、今日はUnityでコルーチンの使い方についてまとめていきます。 コルーチンは関数の実行途中で中断し、指定時間経過後等の条件で再開できる関数のようなものです。 詳細については公式マニュアルの …

no image

PowerShellでトースト通知を送る

確認環境 PSVersion 5.1.18362.1110 トースト通知を送る [Windows.UI.Notifications.ToastNotificationManager, Win …

no image

Unityでアプリケーションのフルスクリーン切り替えキーを無効にする方法

こんにちは、今日はUnityでアプリケーションのフルスクリーン切り替えキーを無効にする方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 フルスクリーン切り替えキーの有効/無 …

no image

PowerShellでアイテムをコピーするコマンドレットCopy-Itemの使い方

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