Provides access to local and remote processes and enables you to start and stop local system processes.
The following example populates a StartInfo with the file to execute, the action performed on it and whether it should displays a user interface. For additional examples, refer to the reference pages for properties of the ProcessStartInfo class.
Classes | |
class | error_data_received_event |
Represents a process error data received event. More... | |
class | exit_event |
Represents a process exit event. More... | |
class | output_data_received_event |
Represents a process output data received event. More... | |
Public Events | |
error_data_received_event | error_data_received |
Occurs when an application writes to its redirected xtd::diagnostics::process::standard_error stream. | |
exit_event | exited |
Occurs when a process exits. | |
output_data_received_event | output_data_received |
Occurs each time an application writes a line to its redirected xtd::diagnostics::process::standard_output stream. | |
Public Constructors | |
process () | |
Initializes a new instance of the xtd::diagnostics::process class. | |
Public Properties | |
int32 | base_priority () const |
Gets the base priority xof the associated process. | |
bool | enable_raising_events () const |
Gets whether the xtd::diagnostics::process::exited event should be raised when the process terminates. | |
process & | enable_raising_events (bool value) |
Sets whether the xtd::diagnostics::process::exited event should be raised when the process terminates. | |
int32 | exit_code () const |
Gets the value that the associated process specified when it terminated. | |
xtd::date_time | exit_time () const |
Gets the time that the associated process exited. | |
intptr | handle () const |
Gets the native handle of the associated process. | |
bool | has_exited () const |
Gets a value indicating whether the associated process has been terminated. | |
int32 | id () const |
Gets the unique identifier for the associated process. | |
string | machine_name () const |
Gets the name of the computer the associated process is running on. | |
xtd::diagnostics::process_priority_class | priority_class () const |
Gets the overall priority category for the associated process. | |
process & | priority_class (xtd::diagnostics::process_priority_class value) |
Sets the overall priority category for the associated process. | |
string | process_name () const |
Gets the name of the process. | |
std::istream & | standard_error () |
Gets a stream used to read the error output of the application. | |
std::ostream & | standard_input () |
Gets a stream used to write the input of the application. | |
std::istream & | standard_output () |
Gets a stream used to read the textual output of the application. | |
const xtd::diagnostics::process_start_info & | start_info () const |
Gets the properties to pass to the xtd::diagnostics::process::start() method of the xtd::diagnostics::process. | |
xtd::diagnostics::process_start_info & | start_info () |
Gets the properties to pass to the xtd::diagnostics::process::start() method of the xtd::diagnostics::process. | |
process & | start_info (const xtd::diagnostics::process_start_info &value) |
Sets the properties to pass to the xtd::diagnostics::process::start() method of the xtd::diagnostics::process. | |
xtd::date_time | start_time () const |
Gets the time that the associated process was started. | |
Public Methods | |
void | close () |
Frees all the resources that are associated with this component. | |
void | kill () |
Immediately stops the associated process. | |
bool | start () |
Starts (or reuses) the process resource that is specified by the xtd::diagnostics::process::start_info property of this Process component and associates it with the component. | |
process & | wait_for_exit () |
Instructs the xtd::diagnostics::process component to wait indefinitely for the associated process to exit. | |
process & | wait_for_exit (int32 milliseconds) |
Instructs the Process component to wait the specified number of milliseconds for the associated process to exit. | |
Public Static Methods | |
static process | start (const xtd::diagnostics::process_start_info &start_info) |
Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new xtd::diagnostics::process component. | |
static process | start (const string &file_name) |
Starts a process resource by specifying the name of a document or application file and associates the resource with a new Process component. | |
static process | start (const string &file_name, const string &arguments) |
Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new xtd::diagnostics::process component. | |
Protected Methods | |
virtual void | on_exited () |
Raises the xtd::diagnostics::process::exited event. | |
Additional Inherited Members | |
![]() | |
object ()=default | |
Create a new instance of the ultimate base class object. | |
virtual bool | equals (const object &obj) const noexcept |
Determines whether the specified object is equal to the current object. | |
virtual xtd::size | get_hash_code () const noexcept |
Serves as a hash function for a particular type. | |
virtual type_object | get_type () const noexcept |
Gets the type of the current instance. | |
template<class object_t > | |
xtd::uptr< object_t > | memberwise_clone () const |
Creates a shallow copy of the current object. | |
virtual xtd::string | to_string () const noexcept |
Returns a xtd::string that represents the current object. | |
![]() | |
template<class object_a_t , class object_b_t > | |
static bool | equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
Determines whether the specified object instances are considered equal. | |
template<class object_a_t , class object_b_t > | |
static bool | reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
Determines whether the specified object instances are the same instance. | |
xtd::diagnostics::process::process | ( | ) |
Initializes a new instance of the xtd::diagnostics::process class.
true
, you can start applications and documents in a way that is similar to using the Run dialog box of the Windows Start menu. When xtd::diagnostics::process_start_info::use_shell_execute is false
, you can start only executables. int32 xtd::diagnostics::process::base_priority | ( | ) | const |
Gets the base priority xof the associated process.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
Windows base_priority | macOS base_priority | linux base_priority | priority_class |
---|---|---|---|
4 | PRIO_MIN (-20) | PRIO_MIN (-20) | xtd::diagnostics::process_priority_class::idle |
6 | PRIO_MIN + (PRIO_MAX - PRIO_MIN) / 4 (-10) | PRIO_MIN + (PRIO_MAX - PRIO_MIN) / 4 (-10) | xtd::diagnostics::process_priority_class::below_normal |
8 | PRIO_MIN + (PRIO_MAX - PRIO_MIN)/2 (0) | PRIO_MIN + (PRIO_MAX - PRIO_MIN)/2 (0) | xtd::diagnostics::process_priority_class::normal |
10 | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 4 (10) | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 4 (10) | xtd::diagnostics::process_priority_class::above_normal |
13 | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 8 (15) | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 8 (15) | xtd::diagnostics::process_priority_class::high |
24 | PRIO_MAX (20) | PRIO_MAX (20) | xtd::diagnostics::process_priority_class::real_time |
bool xtd::diagnostics::process::enable_raising_events | ( | ) | const |
Gets whether the xtd::diagnostics::process::exited event should be raised when the process terminates.
true
if the xtd::diagnostics::process::exited event should be raised when the associated process is terminated (through either an exit or a call to xtd::diagnostics::process::kill()); otherwise, false
. The default is false
. Note that the xtd::diagnostics::process::exited event is raised even if the value of xtd::diagnostics::process::enable_raising_events is false
when the process exits during or before the user performs a xtd::diagnostics::process::has_exited check. true
, or when xtd::diagnostics::process::enable_raising_events is false
and a xtd::diagnostics::process::has_exited check is invoked by the component, the component can access the administrative information for the associated process, which remains stored by the operating system. Such information includes the xtd::diagnostics::process::exit_time and the xtd::diagnostics::process::exit_code. true
, the xtd::diagnostics::process::exited event is raised when the associated process terminates. Your procedures for the xtd::diagnostics::process::exited event run at that time. false
can save system resources. process & xtd::diagnostics::process::enable_raising_events | ( | bool | value | ) |
Sets whether the xtd::diagnostics::process::exited event should be raised when the process terminates.
value | true if the xtd::diagnostics::process::exited event should be raised when the associated process is terminated (through either an exit or a call to xtd::diagnostics::process::kill()); otherwise, false . The default is false . Note that the xtd::diagnostics::process::exited event is raised even if the value of xtd::diagnostics::process::enable_raising_events is false when the process exits during or before the user performs a xtd::diagnostics::process::has_exited check. |
true
, or when xtd::diagnostics::process::enable_raising_events is false
and a xtd::diagnostics::process::has_exited check is invoked by the component, the component can access the administrative information for the associated process, which remains stored by the operating system. Such information includes the xtd::diagnostics::process::exit_time and the xtd::diagnostics::process::exit_code. true
, the xtd::diagnostics::process::exited event is raised when the associated process terminates. Your procedures for the xtd::diagnostics::process::exited event run at that time. false
can save system resources. int32 xtd::diagnostics::process::exit_code | ( | ) | const |
Gets the value that the associated process specified when it terminated.
xtd::invalid_operation_exception | The process has not exited. -or- The process xtd::diagnostics::process::handle is not valid. |
xtd::not_supported_exception | You are trying to access the xtd::diagnostics::process::exit_code property for a process that is running on a remote computer. This property is available only for processes that are running on the local computer. |
true
. To ensure that asynchronous event handling has been completed, call the xtd::diagnostics::wait_for_exit() overload that takes no parameter before checking xtd::diagnostics::has_exited. true
for the xtd::diagnostics::process component to receive notification that the process has exited. xtd::date_time xtd::diagnostics::process::exit_time | ( | ) | const |
Gets the time that the associated process exited.
xtd::not_supported_exception | You are trying to access the xtd::diagnostics::process::exit_time property for a process that is running on a remote computer. This property is available only for processes that are running on the local computer. |
intptr xtd::diagnostics::process::handle | ( | ) | const |
Gets the native handle of the associated process.
xtd::invalid_operation_exception | The process has not been started or has exited. The xtd::diagnostics::process::handle property cannot be read because there is no process associated with this xtd::diagnostics::process instance. -or- The xtd::diagnostics::process instance has been attached to a running process but you do not have the necessary permissions to get a handle with full access rights. |
xtd::not_supported_exception | You are trying to access the xtd::diagnostics::process::handle property for a process that is running on a remote computer. This property is available only for processes that are running on the local computer. |
bool xtd::diagnostics::process::has_exited | ( | ) | const |
Gets a value indicating whether the associated process has been terminated.
true
if the operating system process referenced by the process component has terminated; otherwise, false
. xtd::invalid_operation_exception | There is no process associated with the object. |
xtd::not_supported_exception | You are trying to access the xtd::diagnostics::process::has_exited property for a process that is running on a remote computer. This property is available only for processes that are running on the local computer. |
true
for xtd::diagnostics::process::has_exited indicates that the associated process has terminated, either normally or abnormally. You can request or force the associated process to exit by calling xtd::diagnostics::process::close_main_window or xtd::diagnostics::process::kill. If a handle is open to the process, the operating system releases the process memory when the process has exited, but retains administrative information about the process, such as the handle, exit code, and exit time. To get this information, you can use the xtd::diagnostics::process::exit_code and xtd::diagnostics::process::exit_time properties. These properties are populated automatically for processes that were started by this component. The administrative information is released when all the Process components that are associated with the system process are destroyed and hold no more handles to the exited process. true
. To ensure that asynchronous event handling has been completed, call the xtd::diagnostics::wait_for_exit() overload that takes no parameter before checking xtd::diagnostics::has_exited. int32 xtd::diagnostics::process::id | ( | ) | const |
Gets the unique identifier for the associated process.
xtd::invalid_operation_exception | The process's Id property has not been set. |
string xtd::diagnostics::process::machine_name | ( | ) | const |
Gets the name of the computer the associated process is running on.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
xtd::diagnostics::process_priority_class xtd::diagnostics::process::priority_class | ( | ) | const |
Gets the overall priority category for the associated process.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
Windows base_priority | macOS base_priority | linux base_priority | priority_class |
---|---|---|---|
4 | PRIO_MIN (-20) | PRIO_MIN (-20) | xtd::diagnostics::process_priority_class::idle |
6 | PRIO_MIN + (PRIO_MAX - PRIO_MIN) / 4 (-10) | PRIO_MIN + (PRIO_MAX - PRIO_MIN) / 4 (-10) | xtd::diagnostics::process_priority_class::below_normal |
8 | PRIO_MIN + (PRIO_MAX - PRIO_MIN)/2 (0) | PRIO_MIN + (PRIO_MAX - PRIO_MIN)/2 (0) | xtd::diagnostics::process_priority_class::normal |
10 | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 4 (10) | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 4 (10) | xtd::diagnostics::process_priority_class::above_normal |
13 | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 8 (15) | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 8 (15) | xtd::diagnostics::process_priority_class::high |
24 | PRIO_MAX (20) | PRIO_MAX (20) | xtd::diagnostics::process_priority_class::real_time |
process & xtd::diagnostics::process::priority_class | ( | xtd::diagnostics::process_priority_class | value | ) |
Sets the overall priority category for the associated process.
value | The priority category for the associated process, from which the xtd::diagnostics::process::base_priority of the process is calculated. |
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
Windows base_priority | macOS base_priority | linux base_priority | priority_class |
---|---|---|---|
4 | PRIO_MIN (-20) | PRIO_MIN (-20) | xtd::diagnostics::process_priority_class::idle |
6 | PRIO_MIN + (PRIO_MAX - PRIO_MIN) / 4 (-10) | PRIO_MIN + (PRIO_MAX - PRIO_MIN) / 4 (-10) | xtd::diagnostics::process_priority_class::below_normal |
8 | PRIO_MIN + (PRIO_MAX - PRIO_MIN)/2 (0) | PRIO_MIN + (PRIO_MAX - PRIO_MIN)/2 (0) | xtd::diagnostics::process_priority_class::normal |
10 | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 4 (10) | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 4 (10) | xtd::diagnostics::process_priority_class::above_normal |
13 | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 8 (15) | PRIO_MAX - (PRIO_MAX - PRIO_MIN) / 8 (15) | xtd::diagnostics::process_priority_class::high |
24 | PRIO_MAX (20) | PRIO_MAX (20) | xtd::diagnostics::process_priority_class::real_time |
string xtd::diagnostics::process::process_name | ( | ) | const |
Gets the name of the process.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
std::istream & xtd::diagnostics::process::standard_error | ( | ) |
Gets a stream used to read the error output of the application.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
false
, and you must set xtd::diagnostics::process_start_info::redirect_standard_error to true
. Otherwise, reading from the xtd::diagnostics::process::standard_error stream throws an exception. std::ostream & xtd::diagnostics::process::standard_input | ( | ) |
Gets a stream used to write the input of the application.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::processes object. |
false
, and you must set xtd::diagnostics::process_start_info::redirect_standard_input to true
. Otherwise, writing to the xtd::diagnostics::process::standard_input stream throws an exception. std::istream & xtd::diagnostics::process::standard_output | ( | ) |
Gets a stream used to read the textual output of the application.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
false
, and you must set xtd::diagnostics::process_start_info::redirect_standard_output to true
. Otherwise, reading from the xtd::diagnostics::process::standard_output stream throws an exception. const xtd::diagnostics::process_start_info & xtd::diagnostics::process::start_info | ( | ) | const |
Gets the properties to pass to the xtd::diagnostics::process::start() method of the xtd::diagnostics::process.
true
or the xtd::diagnostics::process::start_info::window_style property value is xtd::diagnostics::process_window_style::hidden. xtd::diagnostics::process_start_info & xtd::diagnostics::process::start_info | ( | ) |
Gets the properties to pass to the xtd::diagnostics::process::start() method of the xtd::diagnostics::process.
true
or the xtd::diagnostics::process::start_info::window_style property value is xtd::diagnostics::process_window_style::hidden. process & xtd::diagnostics::process::start_info | ( | const xtd::diagnostics::process_start_info & | value | ) |
Sets the properties to pass to the xtd::diagnostics::process::start() method of the xtd::diagnostics::process.
value | The xtd::diagnostics::process_start_info that represents the data with which to start the process. These arguments include the name of the executable file or document used to start the process. |
true
or the xtd::diagnostics::process::start_info::window_style property value is xtd::diagnostics::process_window_style::hidden. xtd::date_time xtd::diagnostics::process::start_time | ( | ) | const |
Gets the time that the associated process was started.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
void xtd::diagnostics::process::close | ( | ) |
Frees all the resources that are associated with this component.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
void xtd::diagnostics::process::kill | ( | ) |
Immediately stops the associated process.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
true
) is used, xtd::diagnostics::process::wait_for_exit and xtd::diagnostics::process::has_exited will indicate that exiting has completed after the given process exits, even if all descendants have not yet exited. bool xtd::diagnostics::process::start | ( | ) |
Starts (or reuses) the process resource that is specified by the xtd::diagnostics::process::start_info property of this Process component and associates it with the component.
true
if a process resource is started; false
if no new process resource is started (for example, if an existing process is reused). xtd::invalid_operation_exception | No file name was specified in the xtd::diagnostics::process component's xtd::diagnostics::process::start_info. |
process & xtd::diagnostics::process::wait_for_exit | ( | ) |
Instructs the xtd::diagnostics::process component to wait indefinitely for the associated process to exit.
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
Instructs the Process component to wait the specified number of milliseconds for the associated process to exit.
milliseconds | The amount of time, in milliseconds, to wait for the associated process to exit. A value of 0 specifies an immediate return, and a value of -1 specifies an infinite wait.The amount of time, in milliseconds, to wait for the associated process to exit. A value of 0 specifies an immediate return, and a value of -1 specifies an infinite wait. |
xtd::invalid_operation_exception | There is no process associated with this xtd::diagnostics::process object. |
|
static |
Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new xtd::diagnostics::process component.
The | xtd::diagnostics::process_start_ifo that contains the information that is used to start the process, including the file name and any command-line arguments. |
true
. In this case, the started process may have activated an existing instance of itself and then exited. xtd::invalid_operation_exception | No file name was specified in the startInfo parameter's xtd::diagnostics::process_start_info::file_name property. |
Starts a process resource by specifying the name of a document or application file and associates the resource with a new Process component.
file_name | The name of a document or application file to run in the process. |
true
. In this case, the started process may have activated an existing instance of itself and then exited. xtd::invalid_operation_exception | No file name was specified in the file_name parameter's xtd::diagnostics::process_start_info::file_name property. |
|
static |
Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new xtd::diagnostics::process component.
file_name | The name of a document or application file to run in the process. |
arguments | Command-line arguments to pass when starting the process. |
true
. In this case, the started process may have activated an existing instance of itself and then exited. xtd::invalid_operation_exception | No file name was specified in the file_name parameter's xtd::diagnostics::process_start_info::file_name property. |
|
protectedvirtual |
Raises the xtd::diagnostics::process::exited event.
error_data_received_event xtd::diagnostics::process::error_data_received |
Occurs when an application writes to its redirected xtd::diagnostics::process::standard_error stream.
exit_event xtd::diagnostics::process::exited |
Occurs when a process exits.
true
. true
for the calling application to receive the xtd::diagnostics::process::exited event. output_data_received_event xtd::diagnostics::process::output_data_received |
Occurs each time an application writes a line to its redirected xtd::diagnostics::process::standard_output stream.