Comments (2)
My suggestion, but not sure how to add tests. My fork for the workaround.
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:convert';
import 'dart:io'
show
Process,
ProcessResult,
ProcessSignal,
ProcessStartMode,
ProcessException,
systemEncoding;
import 'package:process/process.dart';
import 'common.dart';
import 'exceptions.dart';
import 'process_manager.dart';
/// Local implementation of the `ProcessManager` interface.
///
/// This implementation delegates directly to the corresponding static methods
/// in `dart:io`.
///
/// All methods that take a `command` will run `toString()` on the command
/// elements to derive the executable and arguments that should be passed to
/// the underlying `dart:io` methods. Thus, the degenerate case of
/// `List<String>` will trivially work as expected.
class LocalProcessManager implements ProcessManager {
/// Creates a new `LocalProcessManager`.
const LocalProcessManager();
@override
Future<Process> start(
List<Object> command, {
String? workingDirectory,
Map<String, String>? environment,
bool includeParentEnvironment = true,
bool runInShell = false,
ProcessStartMode mode = ProcessStartMode.normal,
bool sanitize = true,
}) {
try {
final String executable = _getExecutable(
command,
workingDirectory,
runInShell,
);
return Process.start(
sanitize ? sanitizeExecutablePath(executable) : executable,
_getArguments(command),
workingDirectory: workingDirectory,
environment: environment,
includeParentEnvironment: includeParentEnvironment,
runInShell: runInShell,
mode: mode,
);
} on ProcessException catch (exception) {
throw ProcessPackageException.fromProcessException(exception,
workingDirectory: workingDirectory);
}
}
@override
Future<ProcessResult> run(
List<Object> command, {
String? workingDirectory,
Map<String, String>? environment,
bool includeParentEnvironment = true,
bool runInShell = false,
Encoding stdoutEncoding = systemEncoding,
Encoding stderrEncoding = systemEncoding,
bool sanitize = true,
}) {
try {
final String executable = _getExecutable(
command,
workingDirectory,
runInShell,
);
return Process.run(
sanitize ? sanitizeExecutablePath(executable) : executable,
_getArguments(command),
workingDirectory: workingDirectory,
environment: environment,
includeParentEnvironment: includeParentEnvironment,
runInShell: runInShell,
stdoutEncoding: stdoutEncoding,
stderrEncoding: stderrEncoding,
);
} on ProcessException catch (exception) {
throw ProcessPackageException.fromProcessException(exception,
workingDirectory: workingDirectory);
}
}
@override
ProcessResult runSync(
List<Object> command, {
String? workingDirectory,
Map<String, String>? environment,
bool includeParentEnvironment = true,
bool runInShell = false,
Encoding stdoutEncoding = systemEncoding,
Encoding stderrEncoding = systemEncoding,
bool sanitize = true,
}) {
try {
final String executable = _getExecutable(
command,
workingDirectory,
runInShell,
);
return Process.runSync(
sanitize ? sanitizeExecutablePath(executable) : executable,
_getArguments(command),
workingDirectory: workingDirectory,
environment: environment,
includeParentEnvironment: includeParentEnvironment,
runInShell: runInShell,
stdoutEncoding: stdoutEncoding,
stderrEncoding: stderrEncoding,
);
} on ProcessException catch (exception) {
throw ProcessPackageException.fromProcessException(exception,
workingDirectory: workingDirectory);
}
}
@override
bool canRun(covariant String executable, {String? workingDirectory}) =>
getExecutablePath(executable, workingDirectory, throwOnFailure: false) !=
null;
@override
bool killPid(int pid, [ProcessSignal signal = ProcessSignal.sigterm]) {
return Process.killPid(pid, signal);
}
}
String _getExecutable(
List<dynamic> command, String? workingDirectory, bool runInShell) {
String commandName = command.first.toString();
if (runInShell) {
return commandName;
}
return getExecutablePath(
commandName,
workingDirectory,
throwOnFailure: true,
)!;
}
List<String> _getArguments(List<Object> command) =>
// Adding a specific type to map in order to workaround dart issue
// https://github.com/dart-lang/sdk/issues/32414
command
.skip(1)
.map<String>((dynamic element) => element.toString())
.toList();
from process.dart.
Related Issues (19)
- Give `LocalProcessManager` a `const` constructor...
- ProcessManager.start's first argument should be List<String> not List<dynamic> HOT 4
- Upgrade from comment-based generics syntax HOT 1
- Consider transparently replacing `/` with `\` on Windows in executable path HOT 1
- Dart 2 runtime failures in tests HOT 2
- Pubspec doesn't declare Dart 2.0 SDK support HOT 2
- Please publish a new version, which is compatible with Dart SDK ^2.1.0 HOT 2
- Feature request: Process.reSync(PID) HOT 1
- Child process not killed when program exit HOT 5
- When fs.currentDirectory throws, skip cwd relative search
- ProcessManager.run should check if the executable is an absolute path and not do its attempts to lookup the path etc. if it is HOT 1
- ProcessManager.run signature is inconsistent with LocalProcessManager.run HOT 1
- getExecutablePath should only return executables HOT 1
- Encoding parameters should be nullable HOT 12
- Please add a tag to match the released version in Pub.dev HOT 2
- ProcessManager.run* should throw ProcessException if executable not found HOT 5
- Fix "unverified published" on pub.dev HOT 2
- Where is the record-replay functionality HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from process.dart.