Skip to content

only run in shell when on windows and running a .bat file #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/dart_mcp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- The old `reject` enum value was replaced with a static constant equal
exactly to `decline`, so switches are not affected.
- Add `title` parameter to `Prompt` constructor.
- Only execute sub-processes in a shell if they are `.bat` files.

## 0.3.2

Expand Down
6 changes: 5 additions & 1 deletion pkgs/dart_mcp_server/lib/src/utils/cli_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io' as io;

import 'package:collection/collection.dart';
import 'package:dart_mcp/server.dart';
Expand Down Expand Up @@ -224,7 +225,10 @@ Future<CallToolResult> runCommandInRoot(
final result = await processManager.run(
commandWithPaths,
workingDirectory: workingDir.path,
runInShell: true,
runInShell:
// Required when running .bat files on windows, but otherwise should
// be avoided due to escaping behavior.
io.Platform.isWindows && commandWithPaths.first.endsWith('.bat'),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you doing any escaping of the command/args before here, or does that just happen inside processManager when runInShell is true? (you probably don't want any escaping when this is false).

You might also want to include .cmd for completeness (I didn't in Dart-Code because I know the only Windows shell scripts are flutter.bat).

I don't know how this works for non-Windows. I presume it you use a shell script that has a shebang line it'll just spawn the shell anyway (Dart-Code never uses shell execute for non-Windows).

Copy link
Contributor Author

@jakemac53 jakemac53 Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you doing any escaping of the command/args before here, or does that just happen inside processManager when runInShell is true? (you probably don't want any escaping when this is false).

Nothing is happening before here (or at all by us)

);

final output = (result.stdout as String).trim();
Expand Down