System.Diagnostics.ProcessStartInfo Class

Assembly: System.dll
Namespace: System.Diagnostics
Summary
Specifies a set of values used when starting a process.
C# Syntax:
public sealed class ProcessStartInfo
Remarks
ProcessStartInfo is used in conjunction with the Process component. When you start a process using the Process class, you have access to process information in addition to that available when attaching to a running process.

You can use the ProcessStartInfo class for greater control over the process you start. You must at least set the ProcessStartInfo.FileName property, either manually or using the constructor. The file name is any application or document. Here a document is defined to be any file type that has an open or default action associated with it. You can view registered file types and their associated applications for your computer using the Folder Options dialog available through the operating system. The Advanced button leads to a dialog that shows whether there is an open action associated with a specific registered file type.

In addition, you can set other properties that define actions to take with that file. You can specify a value specific to the type of the ProcessStartInfo.FileName property for the System.Diagnostics.ProcessStartInfo.Verb (not supported on the shared source CLI) property. For example, you can specify "print" for a document type. Additionally, you can specify ProcessStartInfo.Arguments property values to be command line arguments to pass to the file's open procedure. For example, if you specify a text editor application in the ProcessStartInfo.FileName property, you can use the ProcessStartInfo.Arguments property to specify a text file to be opened by the editor.

Standard input is usually the keyboard, and standard output and error are usually the monitor screen. However, you can use the ProcessStartInfo.RedirectStandardInput, ProcessStartInfo.RedirectStandardOutput and ProcessStartInfo.RedirectStandardError properties to cause the process to get input from or return output to a file or other device. If you use the Process.StandardInput, Process.StandardOutput, or Process.StandardError properties on the Process component, you must first set the corresponding value on the ProcessStartInfo property. Otherwise, the system throws an exception when you read or write to the stream.

Set ProcessStartInfo.UseShellExecute to specify whether to start the process using the operating system shell.

You can change the value of any ProcessStartInfo property up to the time that the process starts. After you start the process, changing these values has no effect.

See also:
System.Diagnostics Namespace

System.Diagnostics.ProcessStartInfo Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the ProcessStartInfo class without specifying a file name with which to start the process.
ctor #2 Overloaded:
.ctor(string fileName)

Initializes a new instance of the ProcessStartInfo class and specifies a file name such as an application or document with which to start the process.
ctor #3 Overloaded:
.ctor(string fileName, string arguments)

Initializes a new instance of the ProcessStartInfo class and specifies an application file name with which to start the process, as well as a set of command line arguments to pass to the application.
Public Properties
Arguments Read-write

Gest or sets the set of command line arguments to use when starting the application.
EnvironmentVariables Read-only

Gets search paths for files, directories for temporary files, application-specific options, and other similar information.
FileName Read-write

RedirectStandardError Read-write

Gets or sets a value indicating whether the process's error output is written to the Process instance's Process.StandardError member, enabling you to write to a destination other than the standard error stream (usually the monitor screen). Used to write error data to a file or a log, for example.
RedirectStandardInput Read-write

Gets or sets a value indicating whether the process command input is read from the Process instance's Process.StandardInput member, enabling you to read from a source other than the standard input stream (usually the keyboard). Used to read data from a file, for example.
RedirectStandardOutput Read-write

Gets or sets a value indicating whether the process output is written to the Process instance's Process.StandardOutput member, enabling you to write to a destination other than the standard output stream (usually the monitor screen). Used to write data to a file, for example.
UseShellExecute Read-write

Gets or sets a value indicating whether to use the operating system shell to start the process.
WorkingDirectory Read-write

Gets or sets the initial directory for the process to be started.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Diagnostics.ProcessStartInfo Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the ProcessStartInfo class without specifying a file name with which to start the process.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public ProcessStartInfo();
Remarks
You must set at least the ProcessStartInfo.FileName property before starting the process. The file name is any application or document. In this case, a document is defined to be any file type that has an open or default action associated with it. You can view registered file types and their associated applications for your computer using the Folder Options dialog available through the operating system. The Advanced button leads to a dialog that shows whether there is an open action associated with a specific registered file type.

Optionally, you can also set other properties before starting the process. The System.Diagnostics.ProcessStartInfo.Verb (not supported on the shared source CLI) property supplies actions to take, such as "print", with the file indicated in the ProcessStartInfo.FileName property. The ProcessStartInfo.Arguments property supplies a way to pass command line arguments to the file when the system opens it.

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the ProcessStartInfo class and specifies a file name such as an application or document with which to start the process.
C# Syntax:
public ProcessStartInfo(
   string fileName
);
Parameters:

fileName

An application or document with which to start a process.

Remarks
The file name is any application or document. In this case, a document is defined to be any file type that has an open or default action associated with it. You can view registered file types and their associated applications for your computer using the Folder Options dialog available through the operating system. The Advanced button leads to a dialog that shows whether there is an open action associated with a specific registered file type.

You can change the ProcessStartInfo.FileName property after calling this constructor, up to the time that the process starts. After you start the process, changing these values has no effect.

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the ProcessStartInfo class and specifies an application file name with which to start the process, as well as a set of command line arguments to pass to the application.
C# Syntax:
public ProcessStartInfo(
   string fileName,
   string arguments
);
Parameters:

fileName

An application with which to start a process.

arguments

Command line arguments to pass to the application when the process starts.

Remarks
The file name is any application or document. In this case, a document is defined to be any file type that has an open or default action associated with it. You can view registered file types and their associated applications for your computer using the Folder Options dialog available through the operating system. The Advanced button leads to a dialog that shows whether there is an open action associated with a specific registered file type.

You can change the ProcessStartInfo.FileName or ProcessStartInfo.Arguments properties after calling this constructor, up to the time that the process starts. After you start the process, changing these values has no effect.

Return to top


Property: Arguments (read-write)
Summary
Gest or sets the set of command line arguments to use when starting the application.
C# Syntax:
public string Arguments {get; set;}

Return to top


Property: EnvironmentVariables (read-only)
Summary
Gets search paths for files, directories for temporary files, application-specific options, and other similar information.
C# Syntax:
public StringDictionary EnvironmentVariables {get;}
Remarks

Return to top


Property: FileName (read-write)
C# Syntax:
public string FileName {get; set;}

Return to top


Property: RedirectStandardError (read-write)
Summary
Gets or sets a value indicating whether the process's error output is written to the Process instance's Process.StandardError member, enabling you to write to a destination other than the standard error stream (usually the monitor screen). Used to write error data to a file or a log, for example.
C# Syntax:
public bool RedirectStandardError {get; set;}
Remarks
The Process component communicates with a child process via a pipe. If a child process writes enough data to the pipe to fill the buffer, the child will block until the parent reads the data from the pipe. This can cause deadlock if your application is reading all output to standard error and standard output, for example, using the following C# code.
              Process p = new Process("...", "...");
              p.UseShellExecute = false;
              p.RedirectStandardOutput = true;
              p.Start();
              p.WaitForExit();
              string output = p.StandardOutput.ReadToEnd();
            

In this instance, both the parent and the child processes would be blocked, as the filled pipe prevents the child process from completing, while the parent process is waiting indefinitely for the child process to exit.

This problem can be solved by moving the ReadToEnd() before the WaitForExit() , as follows.

              Process p = new Process("...", "...");
              p.UseShellExecute = false;
              p.RedirectStandardOutput = true;
              p.Start();
              string output = p.StandardOutput.ReadToEnd();
              p.WaitForExit();
            

A similar problem arises if you redirect both standard output and standard error and then try to read both, for example using the following C# code.

              string output = p.StandardOutput.ReadToEnd();
              string error = p.StandardError.ReadToEnd();
              p.WaitForExit();
            

In this case, if the child process writes any text to standard error it will block the process, because the parent process cannot read from standard error until it has finished reading from standard output. However, the parent process will not read from standard output until the process ends. A recommended solution to this situation is to create two threads so that your application can read the output of each stream on a separate thread.

Return to top


Property: RedirectStandardInput (read-write)
Summary
Gets or sets a value indicating whether the process command input is read from the Process instance's Process.StandardInput member, enabling you to read from a source other than the standard input stream (usually the keyboard). Used to read data from a file, for example.
C# Syntax:
public bool RedirectStandardInput {get; set;}

Return to top


Property: RedirectStandardOutput (read-write)
Summary
Gets or sets a value indicating whether the process output is written to the Process instance's Process.StandardOutput member, enabling you to write to a destination other than the standard output stream (usually the monitor screen). Used to write data to a file, for example.
C# Syntax:
public bool RedirectStandardOutput {get; set;}
Remarks
The Process component communicates with a child process via a pipe. If a child process writes enough data to the pipe to fill the buffer, the child will block until the parent reads the data from the pipe. This can cause deadlock if your application is reading all output to standard error and standard output, for example, using the following C# code.
              Process p = new Process("...", "...");
              p.UseShellExecute = false;
              p.RedirectStandardOutput = true;
              p.Start();
              p.WaitForExit();
              string output = p.StandardOutput.ReadToEnd();
            

In this instance, both the parent and the child processes would be blocked, as the filled pipe prevents the child process from completing, while the parent process is waiting indefinitely for the child process to exit.

This problem can be solved by moving the ReadToEnd() before the WaitForExit() , as follows.

              Process p = new Process("...", "...");
              p.UseShellExecute = false;
              p.RedirectStandardOutput = true;
              p.Start();
              string output = p.StandardOutput.ReadToEnd();
              p.WaitForExit();
            

A similar problem arises if you redirect both standard output and standard error and then try to read both, for example using the following C# code.

              string output = p.StandardOutput.ReadToEnd();
              string error = p.StandardError.ReadToEnd();
              p.WaitForExit();
            

In this case, if the child process writes any text to standard error it will block the process, because the parent process cannot read from standard error until it has finished reading from standard output. However, the parent process will not read from standard output until the process ends. A recommended solution to this situation is to create two threads so that your application can read the output of each stream on a separate thread.

Return to top


Property: UseShellExecute (read-write)
Summary
Gets or sets a value indicating whether to use the operating system shell to start the process.
C# Syntax:
public bool UseShellExecute {get; set;}
Remarks
Setting this property to false enables you to redirect input, output, and error streams.

When you use the operating system shell to start processes, you are able to start any document (which is any registered file type associated with an executable that has a default open action) and perform operations on the file, such as printing, with the Process component. When ProcessStartInfo.UseShellExecute is false, you are able to start only executables with the Process component.



Note ProcessStartInfo.UseShellExecute must be true if you set System.Diagnostics.ProcessStartInfo.ErrorDialog (not supported on the shared source CLI) to true.
See also:
ProcessStartInfo.RedirectStandardInput | ProcessStartInfo.RedirectStandardOutput | ProcessStartInfo.RedirectStandardError

Return to top


Property: WorkingDirectory (read-write)
Summary
Gets or sets the initial directory for the process to be started.
C# Syntax:
public string WorkingDirectory {get; set;}
Remarks
If the directory is already part of the system path variable, it is not necessary to repeat the directory's location in this property.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~ProcessStartInfo();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.