process_run 0.6.0-dev.1

  • Readme
  • Changelog
  • Installing
  • 45

process_run.dart #

Process run helpers for Linux/Win/Mac

Build Status

Goals #

Currently using Process.run does not stream output which is not convenient for lenthy operation. It requires using Process.start in a more complex way. run and runCmd add verbose helper for that. Also dart binaries (pub, dart2js...) can be called consistently on Mac/Windows/Linux

ProcessCmd allow creating command object that can be run and modified

Usage #

process_run #

Additional options to Process.run are

  • specifying stdin
  • making it verbose

dartbin #

Helper to format dart binaries argument that works cross-platforms

  • dart2js
  • pub
  • dartfmt
  • dartanalyzer
  • dartoc
  • dartdevc

process_cmd #

Allow creating ProcessCmd object that can be run in different manner

Sample usage #

Using ProcessCmd

import 'dart:io';
import 'package:process_run/cmd_run.dart';

main() async {
  // 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);

  // Running the command in verbose mode (i.e. display the command and stdout/stderr)
  // > $ echo "hello world"
  // > hello world
  await runCmd(cmd, verbose: true);

  // Stream the out to stdout
  await runCmd(cmd, stdout: stdout);

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

  // clone the command to allow other modifications
  cmd = processCmd('echo', ['hello world'], runInShell: runInShell);
  // > $ echo "hello world"
  // > hello world
  await runCmd(cmd, verbose: true);
  // > $ echo "new hello world"
  // > new hello world
  await runCmd(cmd.clone()
    ..arguments = ["new hello world"], verbose: true);

  // Calling dart
  // > $ dart --version
  // > Dart VM version: 1.19.1 (Wed Sep  7 15:59:44 2016) on "linux_x64"
  cmd = dartCmd(['--version']);
  await runCmd(cmd, verbose: true);

  // Calling dart script
  // $ dart example/my_script.dart my_first_arg my_second_arg
  await runCmd(dartCmd(['example/my_script.dart', 'my_first_arg', 'my_second_arg']), commandVerbose: true);

  // Calling pub
  // > $ pub --version
  // > Pub 1.19.1
  await runCmd(pubCmd(['--version']), verbose: true);

  // Listing global activated packages
  // > $ pub global list
  // > ...
  await runCmd(pubCmd(['global', 'list']), verbose: true);
}

Low level

import 'dart:io';

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, stdout: stdout);

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

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

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

Limitations #

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

Changelog #

0.5.6 #

  • supports implicit-casts: false

0.5.5 #

  • when using io.stdout and io.stderr, flush them when running a command

0.5.4 #

  • Fix handling of stdin

0.5.2 #

  • fix dart2js to have a libraryRoot argument
  • add dartdevc

0.5.1 #

  • fix devRun

0.5.0 #

  • deprecated connectStdout and connectStrerr in ProcessCmd
  • add stdin, stdout, verbose and commandVerbose parameter for run

0.4.0 #

  • add stdin and deprecated buggy connectStdin

0.3.3 #

  • add argumentToString to handle basic quote or double quote

0.3.2 #

  • fix dartdoc to add --packages argument along with the snapshot

0.3.0 #

  • Add runCmd (cmd_run library)

0.2.0 #

  • Add ProcessCmd

0.1.0 #

  • Initial version, run and dartbin utilities

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  process_run: ^0.6.0-dev.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:process_run/process_run.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
90
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
45
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.63 <2.0.0