run method Null safety

Future<ProcessResult> run (
  1. String executable,
  2. List<String> arguments,
  3. {String? workingDirectory,
  4. Map<String, String>? environment,
  5. bool includeParentEnvironment: true,
  6. bool runInShell: false,
  7. Encoding? stdoutEncoding: systemEncoding,
  8. Encoding? stderrEncoding: systemEncoding}

Starts a process and runs it non-interactively to completion. The process run is executable with the specified arguments.

Use workingDirectory to set the working directory for the process. Note that the change of directory occurs before executing the process on some platforms, which may have impact when using relative paths for the executable and the arguments.

Use environment to set the environment variables for the process. If not set the environment of the parent process is inherited. Currently, only US-ASCII environment variables are supported and errors are likely to occur if an environment variable with code-points outside the US-ASCII range is passed in.

If includeParentEnvironment is true, the process's environment will include the parent process's environment, with environment taking precedence. Default is true.

If runInShell is true, the process will be spawned through a system shell. On Linux and OS X, /bin/sh is used, while %WINDIR%\system32\cmd.exe is used on Windows.

The encoding used for decoding stdout and stderr into text is controlled through stdoutEncoding and stderrEncoding. The default encoding is systemEncoding. If null is used no decoding will happen and the ProcessResult will hold binary data.

Returns a Future<ProcessResult> that completes with the result of running the process, i.e., exit code, standard out and standard in.

The following code uses to grep for main in the file test.dart on Linux.'grep', ['-i', 'main', 'test.dart']).then((result) {


external static Future<ProcessResult> run(
    String executable, List<String> arguments,
    {String? workingDirectory,
    Map<String, String>? environment,
    bool includeParentEnvironment: true,
    bool runInShell: false,
    Encoding? stdoutEncoding: systemEncoding,
    Encoding? stderrEncoding: systemEncoding});