process_run 0.7.0+1

  • Readme
  • Changelog
  • Installing
  • 83

process_run.dart #

Process run helpers for Linux/Win/Mac

Build Status

Goals #

Currently using 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 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.7.0 #

  • add flutter command support
  • add Windows support
  • add which utility

0.6.0 #

  • dart2 support

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:

  process_run: ^0.7.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter 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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/src/common/dev_utils.dart. (-1.49 points)

Analysis of lib/src/common/dev_utils.dart reported 3 hints:

line 24 col 12: Don't explicitly initialize variables to null.

line 33 col 5: Use rethrow to rethrow a caught exception.

line 38 col 11: Don't explicitly initialize variables to null.

Fix lib/process_run.dart. (-0.50 points)

Analysis of lib/process_run.dart reported 1 hint:

line 42 col 7: Use isEmpty instead of length

Maintenance suggestions

Package is getting outdated. (-38.63 points)

The package was last published 72 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and process_run.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58 <3.0.0
collection >=1.14.10 <3.0.0 1.14.12
path >=1.6.1 <3.0.0 1.6.4
Dev dependencies
args any
async any
build_runner >=0.9.0
build_test >=0.10.2
dev_test any
pub_semver any
test >=1.2.0