Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

dt run on Windows crashes horribly with ProcessException: The system cannot find the file specified

未关闭
#9,717 5 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
dart

调研方向

从 tool/lib/commands/serve.dart 第247行附近开始,并在按照文档完成 Dart SDK 设置后,在 Windows 上重现 dt run。跟踪 gclient sync 命令的启动方式,并将该行为与 Windows 批处理文件的要求进行比较;当 dt run 能够在不出现 ProcessException 的情况下启动服务器和前端,并且所需的设置已记录在文档中时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

bug infra P3

After setting up devtools on Windows properly, running dt run in the root directory to start the devtools server and frontend fails horribly with the following:

[serve] running gclient sync in the local dart sdk
C:\Users\User\Downloads\VSCode\dart-lang\sdk > gclient sync
ProcessException: The system cannot find the file specified (at ../../runtime/bin/process_win.cc:577)
  Command: gclient sync
#0      _ProcessImpl._start (dart:io-patch/process_patch.dart:411:33)
#1      Process.start (dart:io-patch/process_patch.dart:42:20)
#2      ProcessManager.spawn (package:io/src/process_manager.dart:78:32)
#3      DevToolsProcessManagerExtension.runProcess (package:devtools_tool/utils.dart:143:27)
#4      ServeCommand.run (package:devtools_tool/commands/serve.dart:246:26)
#5      CommandRunner.runCommand (package:args/command_runner.dart:212:27)
#6      DevToolsCommandRunner.runCommand (package:devtools_tool/devtools_command_runner.dart:92:18)
#7      CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:122:25)
#8      new Future.sync (dart:async/future.dart:325:27)
#9      CommandRunner.run (package:args/command_runner.dart:122:14)
#10     main (file:///C:/Users/User/Downloads/VSCode/devtools/tool/bin/dt.dart:15:10)
#11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:312:33)
#12     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)

ProcessException: Failed with exit code: 1.
  Command: C:\Users\User\Downloads\VSCode\devtools\tool\flutter-sdk\bin\dart.bat C:\Users\User\Downloads\VSCode\devtools\tool\bin\dt.dart serve --run-app
#0      DevToolsProcessManagerExtension.runProcess (package:devtools_tool/utils.dart:152:7)
<asynchronous suspension>
#1      RunCommand.run (package:devtools_tool/commands/run.dart:34:21)
<asynchronous suspension>
#2      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#3      SharedStdIn.terminate (package:io/src/shared_stdin.dart:91:3)
<asynchronous suspension>
#4      main (file:///C:/Users/User/Downloads/VSCode/devtools/tool/bin/dt.dart:14:28)
<asynchronous suspension>

I debugged this for quite a while and it appears that the code at https://github.com/flutter/devtools/blob/cac09a934e33e7e4b18cf3af5d4c9514fafd2077/tool/lib/commands/serve.dart#L247 attempts to run gclient sync as a process, which is ultimately implemented as a CreateProcessW call in the deepest darkest parts of the Dart VM. It's important to note that in this case, the gclient executable we are trying to run is a batch file (As depot_tools does not support running the gclient executable in anything but cmd on Windows, meaning the shell script version can be disregarded, although even if it was supported, there would be no difference, as is later explained). However, the Windows documentation states

To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.

The reason for this becomes apparent once you realize that CreateProcessW, regardless of the several different ways you can call it, only ever expects exe files when no file extension is given. So when that runProcess call is executed during dt run, what Windows is actually looking for is a gclient.exe, not gclient.bat as is actually intended. This in turn ends up making the attempt to run the gclient process explode. Tracking the CreateProcessW call from the Dart VM confirms this, as the paths shown are all variants of C:\Users\User\Downloads\VSCode\depot_tools\gclient.exe or C:\Users\User\Downloads\VSCode\depot_tools\gclient sync.exe for every entry in PATH, since Windows is trying and failing to find gclient.exe in each directory listed in PATH (The latter is because Windows is desperately trying to find an executable to make the user code happy, and in its desperation, since the application name parameter is not specified to CreateProcessW by the Dart VM, it interprets the entire gclient sync command as the executable name itself)

I don't know how best to fix this. The optimal fix would be to run cmd.exe /c gclient.bat as the CreateProcessW documentation suggests, but the Dart VM does not expose any way for the first parameter of the CreateProcessW call to be set from Dart, instead hardcoding it to nullptr while it uses the second process arguments parameter as the name of the process itself. Maybe a hack could be put in place for Windows in the devtools, given that a full fix requires rearchitecting the Dart VM's process code and the API it exposes quite a bit.

One other thing I also noticed is that the documention for devtools for running both server and frontend implies that simply cloning the Dart SDK is enough, but the actual code suggests something very different, namely that you seem to need depot_tools, particularly gclient, as well as having cloned Dart using fetch from depot_tools rather than just regular git clone.

主要语言
Dart
星标
1.7k
派生
408
平均合并
4 天 15 小时
30 天内合并 PR
10

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

flutter/devtools 的其他 Issue

查看 flutter/devtools 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。