1

After building the Dart application, function Process.run starts to open a visible cmd for a second-two.

final bool checkEnvironment = environment == ShellEnvironment.powershell;
ProcessResult result = await Process.run(
  checkEnvironment ? 'powershell' : command,
  checkEnvironment ? [command] : args,
  runInShell: checkEnvironment,
);

Link with example(gif): https://i.stack.imgur.com/orSzG.jpg For each command it opens a new cmd window.

If i launch the application with idea(not a build version) - such thing does not happen

Also tried this version - still the same problem:

final bool checkEnvironment = environment == ShellEnvironment.powershell;
ProcessResult result = await Process.run(
  'start',
   checkEnvironment ? ['/min', 'powershell', '-command', command] : ['/min', 'cmd', '/c', command],
   runInShell: true,
);

Found an article that runInShell creates a new window so i removed it, but the result is still the same.

final bool checkEnvironment = environment == ShellEnvironment.powershell;
ProcessResult result = await Process.run(
  checkEnvironment ? 'powershell.exe' : 'cmd',
  checkEnvironment ? ['-command', command] : ['/c', command],
);
Kirill
  • 1,129
  • 1
  • 7
  • 16
  • Showing a console window is normal behavior on Windows when running console-mode programs. For PowerShell, [How to run a PowerShell script without displaying a window?](https://stackoverflow.com/q/1802127/) possibly could help you. If you're trying to execute a `.bat`/`.cmd` script, then [Hide Command Window of .BAT file that Executes Another .EXE File](https://stackoverflow.com/q/507347/) or [How to avoid command window popping on cmd.exe](https://stackoverflow.com/q/17244579/) maybe would help. – jamesdlin Apr 13 '21 at 23:20
  • None of this is helpful – Kirill Apr 14 '21 at 09:52

1 Answers1

8

You might have found a solution here: https://github.com/flutter/flutter/issues/47891. BUT do not use it! It does not work with window 7 and creates a problem when after closing the app user cannot delete the app due to one instance of CMD is still running.

Try this approach instead

// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
  CreateAndAttachConsole();
} else {
  AllocConsole();
  ShowWindow(GetConsoleWindow(), SW_HIDE);
}

You can replace it in windows/runner/main.cpp

Kirill
  • 1,129
  • 1
  • 7
  • 16