Skip to content

"The terminal process terminated with exit code: 1" on Windows when running CLI apps in the terminal #2750

Closed

Description

@piechowiakmichal

Hello, I have such a simple code in Dart:

import 'dart:io';

void main() {
  print('How old are you?');

  String age = stdin.readLineSync();
  print('You have $age age');
}

When I run it using cmd, it fires up normally, ie it prints the first print, gets the keyboard input, and prints the second print. When I run it with VS Code, the script prints the first print and then reads the keyboard data in a loop, it doesn't go to the second print.

I fixed it by configuring launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Dart",
            "program": "${file}",
            "request": "launch",
            "type": "dart",
            "console": "terminal"
        }
    ]
}

I added "console": "terminal".

Now the program starts, but as soon as the program finishes, the terminal crashes and gets an error:

The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" terminated with exit code: 1.

The same thing happens with cmd:

The terminal process "C:\WINDOWS\System32\cmd.exe" terminated with exit code: 1.

What can I do to make the program run after clicking F5, execute correctly and not to turn off the terminal immediately after executing the program?

In the attachment there is Dart: Capture Logs.
Dart-Code-Log-2020-07-06 11-56-43.txt

Activity

  1. added this to the v3.14.0 milestone on Aug 31, 2020
  2. DanTup commented on Aug 31, 2020

    @DanTup
    Member

    Thanks - I'm able to reproduce this on Windows.

  3. changed the title [-]Problem with debug console and stdin[/-] [+]"The terminal process terminated with exit code: 1" on Windows when running CLI apps in the terminal[/+] on Aug 31, 2020
  4. DanTup commented on Aug 31, 2020

    @DanTup
    Member

    After much debugging, I've managed to track down what's happening here. When we ask VS Code to run the process in the terminal, we collect the process ID in case we need to terminate it (for example if you click Stop on the debug toolbar):

    resolve(new RemoteEditorTerminalProcess(resp.body.processId || resp.body.shellProcessId));
    

    We fall back to the shell ID if it doesn't give us the process ID. Then when the app finishes in the shell, VS Code asks us to terminate and we end up terminating the shell. I'm guessing on macOS we end up with the real process ID (or, terminating the shell doesn't get reported as an error in this way).

    I have some ideas about how to fix, I'll do some testing. Thanks!

  5. DanTup commented on Aug 31, 2020

    @DanTup
    Member

    There's a new beta version at https://github.com/Dart-Code/Dart-Code/releases/tag/v3.14.0-beta.2 if you want to try it out. If you install the beta, you'll be automatically migrating back to stable releases once it goes out.

    Thanks!

  6. piechowiakmichal commented on Aug 31, 2020

    @piechowiakmichal
    Author

    Everything works correctly. I tested using Powershell and CMD as default console in VS Code.

    Thank you for helping me so quickly!

  7. DanTup commented on Sep 1, 2020

    @DanTup
    Member

    Great, thanks for confirming (and reporting)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in debuggingRelates to the debug adapter or process of running debug sessionsis bugon windows

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions