パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v4.2.4

process_runner

Dart向けのプロセス呼び出し抽象で、マルチプロセスキューを管理します。

AndroidiOSmacOSWindowsLinux
30日間ダウンロード
61.3万
いいね数
27
Pub ポイント
150

パッケージをインストール

flutter pub add process_runner

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

process_runner は、システムプロセスの実行と管理を抽象化するためのDartパッケージであり、特に制御されたキューで複数のプロセスを処理する際に有用です。非同期実行、出力のキャプチャ、エラー処理などの機能により、プロセス呼び出しを簡素化します。クロスプラットフォーム対応で、Android、iOS、macOS、Windows、Linuxをサポートしており、外部コマンドの実行が必要なデスクトップおよびデバイスレベルのアプリケーションに最適です。このパッケージはGoogleによってメンテナンスされており、Flutterプロジェクトにシームレスに統合できます。

用途

  • Flutterアプリからシェルコマンドを実行する
  • システムプロセスを介したバックグラウンドタスクの管理
  • ビルドまたはデプロイスクリプトの自動化
  • CI/CDパイプラインで外部ツールを実行する
  • 長時間実行されるプロセス操作の処理

主な機能

  • マルチプロセスキュー
  • 非同期プロセス管理
  • 出力およびエラー ストリームの処理
  • クロスプラットフォーム互換性
  • プロセス実行のためのシンプルな API

適している対象

  • デスクトップアプリ開発者
  • CI/CD自動化ツール
  • DevTools とビルドシステム
  • システムレベルの統合
  • シェルコマンドのサポートが必要なFlutterアプリ

注意事項

  • 外部プロセスの障害に対する適切なエラーハンドリングが必要です
  • 一部のプラットフォームでは、権限の昇格が必要になる場合があります
  • 高周波の短期間プロセスには適していません
  • 追加のラッパーなしで同期実行パターンに限定
  • 下位のOSプロセス機能に依存する

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Process

The process_runner package for Dart uses the ProcessManager class from process package to allow invocation of external OS processes, and manages the stderr and stdout properly so that you don't lose any output, and can easily access it without needing to wait on streams.

Like dart:io and process, it supplies a rich, Dart-idiomatic API for spawning OS processes, with the added benefit of easy retrieval of stdout and stderr from the result of running the process, with proper waiting for the process and stderr/stdout streams to be closed. Because it uses process, you can supply a mocked ProcessManager to allow testing of code that uses process_runner.

In addition to being able to launch processes separately with ProcessRunner, it allows creation of a pool of worker processes with ProcessPool, and manages running them with a set number of active WorkerJobs, and manages the collection of their stdout, stderr, and interleaved stdout and stderr output.

See the example and process_runner library docs for more information on how to use it, but the basic usage for is:

import 'package:process_runner/process_runner.dart';

Future<void> main() async {
  ProcessRunner processRunner = ProcessRunner();
  ProcessRunnerResult result = await processRunner.runProcess(['ls']);

  print('stdout: ${result.stdout}');
  print('stderr: ${result.stderr}');

  // Print interleaved stdout/stderr:
  print('combined: ${result.output}');
}

For the ProcessPool, also see the example, but it basically looks like this:

import 'package:process_runner/process_runner.dart';

Future<void> main() async {
  ProcessPool pool = ProcessPool(numWorkers: 2);
  final List<WorkerJob> jobs = <WorkerJob>[
    WorkerJob(['ls'], name: 'Job 1'),
    WorkerJob(['df'], name: 'Job 2'),
  ];
  await for (final WorkerJob job in pool.startWorkers(jobs)) {
    print('\nFinished job ${job.name}');
  }
}

Or, if you just want the answer when it's done:

import 'package:process_runner/process_runner.dart';

Future<void> main() async {
  ProcessPool pool = ProcessPool(numWorkers: 2);
  final List<WorkerJob> jobs = <WorkerJob>[
    WorkerJob(['ls'], name: 'Job 1'),
    WorkerJob(['df'], name: 'Job 2'),
  ];
  List<WorkerJob> finishedJobs = await pool.runToCompletion(jobs);
  for (final WorkerJob job in finishedJobs) {
    print("${job.name}: ${job.result.stdout}");
  }
}

process_runner utility

The example can also be installed and run as a useful command-line utility. You can install it using:

dart pub global activate process_runner

And you can run it with:

dart pub global run process_runner

The above steps will work on any Dart-supported platform.

Of course, you can also just compile the example into a native executable and move it to a directory in your PATH:

dart compile exe bin/process_runner.dart -o process_runner
mv process_runner /some/bin/dir/in/your/path

The usage for the utility is as follows:

process_runner [--help] [--quiet] [--report] [--stdout] [--stderr]
               [--run-in-shell] [--working-directory=<working directory>]
               [--jobs=<num_worker_jobs>] [--command="command" ...]
               [--source=<file|"-"> ...]:
-h, --help                 Print help for process_runner.
-q, --quiet                Silences the stderr and stdout output of the
                           commands. This is a shorthand for "--no-stdout
                           --no-stderr".
-r, --report               Print progress on the jobs to stderr while running.
    --[no-]stdout          Prints the stdout output of the commands to stdout in
                           the order they complete. Will not interleave lines
                           from separate processes. Has no effect if --quiet is
                           specified.
                           (defaults to on)
    --[no-]stderr          Prints the stderr output of the commands to stderr in
                           the order they complete. Will not interleave lines
                           from separate processes. Has no effect if --quiet is
                           specified
                           (defaults to on)
    --run-in-shell         Run the commands in a subshell.
    --[no-]fail-ok         If set, allows continuing execution of the remaining
                           commands even if one fails to execute. If not set,
                           ("--no-fail-ok") then process will just exit with a
                           non-zero code at completion if there were any jobs
                           that failed.
-j, --jobs                 Specify the number of worker jobs to run
                           simultaneously. Defaults to the number of processor
                           cores on the machine.
    --working-directory    Specify the working directory to run in.
                           (defaults to ".")
-c, --command              Specify a command to add to the commands to be run.
                           Commands specified with this option run before those
                           specified with --source. Be sure to quote arguments
                           to --command properly on the command line.
-s, --source               Specify the name of a file to read commands from, one
                           per line, as they would appear on the command line,
                           with spaces escaped or quoted. Specify "--source -"
                           to read from stdin. More than one --source argument
                           may be specified, and they will be concatenated in
                           the order specified. The stdin ("--source -")
                           argument may only be specified once.

カテゴリー

依存関係

依存関係一覧 8 件

ソースリポジトリ

このパッケージを使用しているプロジェクト