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 – UIのButtonにイベントを設定する方法まとめ

こんにちは、今日はUnityでUIのButtonクリック時に発生するイベントを設定する方法についてまとめていきます。 HierarchyウィンドウからCreate > UI > Buttonを選択や、 …

no image

PowerShellで現在の文字セットを確認&変更する方法

確認環境 PSVersion 5.1.18362.1171 文字セットを確認 以下のようにchcpコマンドを使用すると、現在のコンソールで設定されている文字セットを表す数値である、コードページが確認で …

no image

Unityで実行環境の情報を取得する方法

System.Environmentクラスで現在の環境についての情報が取得できます。 OSバージョン System.OperatingSystem os = System.Environment.OS …

no image

PowerShellでホストプログラムを取得するコマンドレットGet-Hostの使い方

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

no image

Windows10のタスクスケジューラでPowerShellスクリプト実行時にウィンドウを表示しないようにする

こんにちは、今日はタスクスケジューラでPowerShellスクリプト実行時にウィンドウを表示しないようにする方法についてまとめていきます。 確認環境 タスク スケジューラ バージョン: 1.0 JSc …