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

Unityでアプリケーションがフォーカスされていない場合に一時停止するかの設定

こんにちは、今日はUnityでアプリケーションがフォーカスされていない場合に一時停止するかの設定についてまとめていきます。 確認環境 Unity 2018.4.15f1 設定方法 Edit > Pro …

no image

PowerShellでエクスプローラーと同じ並びでファイルのリストを取得する

こんにちは、今日はPowerShellでエクスプローラーと同じ並びでファイルのリストを取得する方法についてまとめていきます。 確認環境 PSVersion 5.1.18362.1110 ファイル一覧取 …

no image

PowerShellでコマンドのあるパスを取得する

確認環境 PowerShell 5.1 コマンドのパスを取得する Get-Commandコマンドレットにコマンド名を渡すと、Source列にてそのコマンドのパスが確認できます。 PS C:\Users …

no image

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

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

no image

PowerShellでコマンド実行結果をテキストファイルに保存する

以下のようにパイプでOut-Fileコマンドレットに結果を渡すか、>演算子を用いて出力先のファイルを指定します。 PS C:\Users\santerabyte> Get-ChildItem | …