패키지, 저장소 및 앱 카테고리 검색

패키지 상세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 및 빌드 시스템
  • 시스템 레벨 통합
  • 쉘 명령어 지원이 필요한 플러터 앱

고려 사항

  • 외부 프로세스 실패에 대한 적절한 오류 처리가 필요합니다
  • 일부 플랫폼에서는 권한을 높여야 할 수 있습니다
  • 고주파 단기 프로세스에 적합하지 않습니다
  • 추가 래퍼 없이 동기 실행 패턴에 한정
  • 기저 운영 체제 프로세스 기능에 따라 다름

원본 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 개

소스 저장소

이 패키지를 사용하는 프로젝트