語言

Process.Run 方法

定義

多載

名稱 Description
Run(ProcessStartInfo, Nullable<TimeSpan>)

啟動由 描述的 startInfo程序,等待其退出,並回傳其退出狀態。

Run(String, IEnumerable<String>, Boolean, Nullable<TimeSpan>)

啟動一個以指定檔案名稱和可選參數的程序,等待它退出,然後回傳其退出狀態。

Run(ProcessStartInfo, Nullable<TimeSpan>)

來源:
Process.Scenarios.cs

啟動由 描述的 startInfo程序,等待其退出,並回傳其退出狀態。

[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.ProcessExitStatus Run(System.Diagnostics.ProcessStartInfo startInfo, TimeSpan? timeout = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member Run : System.Diagnostics.ProcessStartInfo * Nullable<TimeSpan> -> System.Diagnostics.ProcessExitStatus
Public Shared Function Run (startInfo As ProcessStartInfo, Optional timeout As Nullable(Of TimeSpan) = Nothing) As ProcessExitStatus

參數

startInfo
ProcessStartInfo

那個 ProcessStartInfo 包含啟動流程所使用的資訊。

timeout
Nullable<TimeSpan>

等待流程結束的最大等待時間。 當 null,則無限期等待。 若程序未在指定逾時內退出,則終止。

傳回

流程的退出狀態。 若程序因逾時而終止, Canceled 則為 true。

屬性

例外狀況

timeout截斷為整數毫秒後,小於 -1 或大於 MaxValue。

startInfo 是 null。

UseShellExecute 設定為 true。

-或者-

RedirectStandardInput, , RedirectStandardOutput或 RedirectStandardError 設為 true。 改用對應的標準把柄屬性來提供把柄。

適用於

Run(String, IEnumerable<String>, Boolean, Nullable<TimeSpan>)

來源:
Process.Scenarios.cs

啟動一個以指定檔案名稱和可選參數的程序,等待它退出,然後回傳其退出狀態。

[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.ProcessExitStatus Run(string fileName, System.Collections.Generic.IEnumerable<string>? arguments = default, bool silent = false, TimeSpan? timeout = default);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member Run : string * seq<string> * bool * Nullable<TimeSpan> -> System.Diagnostics.ProcessExitStatus
Public Shared Function Run (fileName As String, Optional arguments As IEnumerable(Of String) = Nothing, Optional silent As Boolean = false, Optional timeout As Nullable(Of TimeSpan) = Nothing) As ProcessExitStatus

參數

fileName
String

執行檔名稱作為起始。

arguments
IEnumerable<String>

命令列參數,傳遞給程序。 通過 null 或空序列即可啟動程序,無需額外參數。

silent
Boolean

當 true時,會將標準輸入、輸出和錯誤導向到空裝置,確保程序不會產生可見的主控台輸出。 當 false時,程序繼承父程序的標準句柄。

timeout
Nullable<TimeSpan>

等待流程結束的最大等待時間。 當 null,則無限期等待。 若程序未在指定逾時內退出,則終止。

傳回

流程的退出狀態。 若程序因逾時而終止, Canceled 則為 true。

屬性

例外狀況

timeout截斷為整數毫秒後,小於 -1 或大於 MaxValue。

fileName 是 null。

fileName 空無一人。

適用於