feat: try to get default windows shell

This commit is contained in:
Chen Asraf
2022-08-07 23:27:02 +03:00
parent ff093f1974
commit 942827e367
2 changed files with 16 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import 'dart:io';
import 'dart:io' as io;
import 'package:file/file.dart';
import 'package:file/local.dart';
@@ -93,7 +93,7 @@ class RunnableScript {
final effectiveArgs = args + extraArgs;
// final argsStr = effectiveArgs.map(_wrap).join(' ');
var config = await ScriptRunnerConfig.get(_fileSystem);
final shell = config.shell ?? '/bin/sh';
final shell = config.shell ?? _getPlatformShell();
final preRun = preloadScripts
.map((d) => 'alias ${d.name}=\'dartsc ${d.name}\'')
@@ -105,7 +105,7 @@ class RunnableScript {
// print("Before parse $cmd $args");
try {
final result = await Process.start(
final result = await io.Process.start(
shell,
[
'-c',
@@ -115,15 +115,15 @@ class RunnableScript {
workingDirectory: workingDir ?? config.workingDir,
);
result.stdout.listen((event) {
stdout.write(String.fromCharCodes(event));
io.stdout.write(String.fromCharCodes(event));
});
result.stderr.listen((event) {
stdout.write(String.fromCharCodes(event));
io.stdout.write(String.fromCharCodes(event));
});
final exitCode = await result.exitCode;
if (exitCode != 0) {
// final stack = StackTrace.current;
final e = ProcessException(
final e = io.ProcessException(
cmd, args, 'Process exited with error code: $exitCode', exitCode);
throw e;
}
@@ -131,6 +131,13 @@ class RunnableScript {
rethrow;
}
}
static String _getPlatformShell() {
if (io.Platform.isWindows) {
return 'cmd.exe';
}
return '/bin/sh';
}
}
String _wrap(String arg) {

View File

@@ -1,7 +1,7 @@
name: script_runner
description: Run all your project-related scripts in a portable, simple config.
version: 0.1.3
homepage: https://casraf.blog/dart-script-runner/
version: 0.1.4
homepage: https://casraf.blog/
repository: https://github.com/chenasraf/dart_script_runner
license: MIT
environment:
@@ -28,7 +28,7 @@ script_runner:
- 'Hello World'
description: test script foobar
- name: activate-local
cmd: dart pub global activate --source path ~/Dev/script_runner
cmd: dart pub global activate --source path ./
- name: combined
cmd: echo 'test' && echo1 && echo2
- short: echo 'this is a short script'