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

PowerShellで現在のディレクトリを表示するコマンドレットGet-Locationの使い方

こんにちは、今日はPowerShellで現在のディレクトリを表示するコマンドレットGet-Locationの使い方についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 …

no image

Unity – Consoleウィンドウにログを表示する方法まとめ

こんにちは、今日はUnityでConsoleウィンドウにログを表示する方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 ログの出力 ログの出力にはUnityEngine.D …

no image

PowerShellで指定オブジェクトを次のコマンドに送信するコマンドレットWrite-Outputの使い方

こんにちは、今日は指定オブジェクトをパイプラインの次のコマンドに送信するコマンドレットWrite-Outputの使い方についてまとめていきます。 このコマンドがパイプラインの最後のコマンドである場合は …

no image

UnityでIMGUIのウィンドウを表示するGUI.Windowの使い方

こんにちは、今日はUnityでIMGUIのウィンドウを表示するGUI.Windowの使い方についてまとめていきます。 確認環境 Unity 2018.4.15f1 GUI.Windowの使い方 以下の …

no image

Unityで引数に最も近い整数を返す関数Mathf.Round

確認環境 Unity 2018.4.15f1 使い方 float num = Mathf.Round(1.2f); Debug.Log(num); float型の数値を渡すと、その値に最も近い整数値を …