std 2025.430.2012 copy "std: ^2025.430.2012" to clipboard
std: ^2025.430.2012 copied to clipboard

[std] A dependncy less dart package (CommandRunner etc).

std #

Pub

CommandRunner is a wrapper over dart:io [Process] API's that supports features like environment management, user switches, and more.

Useful for writing shell utility scripts in Dart, or within applications that perform system administration tasks on behalf of other users.

import 'dart:io';
import 'package:std/command_runner.dart';

main() async {
  var shell = CommandRunner(useUnixShell: true);

  // Pipe results to string, easily.
  // Without `silent: true', stdout is echoed automatically although you get stdout as method result.
  String echo = await shell.run('echo hello world', silent: true);
  print(echo);

  // You can run a program, and expect a certain exit code.
  //
  // Use `returnCode: true' to get process exit code.
  //
  // Otherwise, a Error is thrown.
  int find = await shell.run$(
    ['find', '.', '-name', '"*.dart"'],
    autoQuote: false,
    returnCode: true,
  );
  print(find);
  if (find != 0) {
    exit(find);
  }

  // You can also run a process and immediately receive a string.
  String pwd = await shell.run('pwd');
  print('cwd: `$pwd`');

  Directory.current = './lib';
  pwd = await shell.run('pwd');
  print('cwd: `$pwd`');

  // You can use | within command line (when CommandRunner() was constructed with `useUnixShell: true'.
  String find2 = await shell.run('find . -name "*.dart" | wc -l');
  print(find2);

  // You can use | within command line (when CommandRunner() was constructed with `useUnixShell: true'.
  // run$() quotes all of the arguments; so in order to use pipe (|) you need to specify `autoQuote: false'.
  String find3 = await shell.run$([
    'find',
    '.',
    '-name',
    '"*.dart"',
    '|',
    'wc',
    '-l',
  ], autoQuote: false);
  print(find3);
}
0
likes
0
points
379
downloads

Publisher

unverified uploader

Weekly Downloads

[std] A dependncy less dart package (CommandRunner etc).

Repository (GitHub)
View/report issues

Topics

#cli #process

License

unknown (license)

More

Packages that depend on std