process_run 0.3.2
process_run: ^0.3.2

outdated Dart 2 incompatible

Process run helpers for Linux/Win/Mac

process_run.dart #

Process run helpers for Linux/Win/Mac

Build Status

Usage #

process_run #

Additional options to Process.run are

  • connecting stdin
  • connecting stdout
  • connecting sterr

dartbin #

Helper to format dart binaries argument that works cross-platforms

  • dart2js
  • pub
  • dartfmt
  • dartanalyzer
  • dartoc

Sample usage #

Using ProcessCmd

// Simple echo command
// Somehow windows requires runInShell for the system commands
bool runInShell = Platform.isWindows;

// Run the command
ProcessCmd cmd = processCmd('echo', ['hello world'], runInShell: runInShell);
await runCmd(cmd);
// Stream the out to stdout
await runCmd(cmd..connectStdout = true);

// Calling dart
cmd = dartCmd(['--version']);
await runCmd(cmd);

// stream stderr
// clone the command to allow other modifications
await runCmd(cmd.clone()..connectStderr = true);
// stream stdout
await runCmd(cmd.clone()..connectStdout = true);

Low level

import 'package:process_run/process_run.dart';
import 'package:process_run/dartbin.dart';

main() async {
  // Simple echo command
  // Somehow windows requires runInShell for the system commands
  bool runInShell = Platform.isWindows;

  // Run the command
  await run('echo', ['hello world'], runInShell: runInShell);

  // Stream the out to stdout
  await run('echo', ['hello world'],
      runInShell: runInShell, connectStdout: true);

  // Calling dart
  await run(dartExecutable, ['--version']);

  // stream the output to stderr
  await run(dartExecutable, ['--version'], connectStderr: true);

  // Listing global activated packages
  await run(dartExecutable, pubArguments(['global', 'list']),
      connectStdout: true);
}

Limitations #

As noted in the example, windows requires runInShell for system commands (echo, type) but not for regular executables (dart, git...)