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

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

example/example.dart

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

Future<void> 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
160
points
1.08k
downloads

Publisher

unverified uploader

Weekly Downloads

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

Repository (GitHub)

Topics

#cli #process

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

archive, crypto, encrypt, http, intl, path, system_info2, uuid

More

Packages that depend on std