Dart 프로그램을 작성 도중 콘솔에서 값을 받아서 사용하라는 요구 사항에 stdin 라이브러리의 readLineSync() 메서드를 사용하고 있었다. 간단하게 String? 타입으로 customer 라는 변수에 입력 값을 받아 사용하고 싶었으나 전혀... 아무런 동작을 안한다.
readLineSync() 이후로 동작을 안 하는 듯한 느낌이라 이유를 찾아봤다.
처음에는 Dart 의 api 사용 방법을 모르나? 싶어서 예제도 찾아보고 encoding 설정도 직접해보고 콘솔 출력을 위해 stdout 으로 찍어보려 했으나 아무것도 안 보인다.
intellJ 나 eclipse 같은 다른 ide 에서 console 입출력 했을 때랑 달라서 혹시..? vscode 는 다른가?
ㄴ>ㅇㅇ 그거임
문제
The Debug Console has more functionality because the process is controlled by the debug adapter, but is unable to accept input from the user via stdin.
VS Code 의 'Debug Console' 은 프로세스가 디버그 어댑터에 의해 제어되기 때문에 사용자로부터 입력을 받을 수 없다.
따라서 terminal 에서 input 을 받을수 있도록 기본 cli console 을 바꿔야 한다.
해결
1. File > Preferences > Settings 으로 이동
2. 'Dart Cli console' 으로 검색 후 debugConsole 에서 teminal 로 변경 한다.
위 처럼 변경하고 run 돌리면 terminal 에서 입력값을 받을 수 있다.
참고 - https://stackoverflow.com/questions/69908923/debug-dart-output-not-printing/69911118#69911118
Debug DART output not printing
Output display user input integer, instead of Even or Odd import 'dart:io'; void main() { print('Enter your number: '); int n = int.parse(stdin.readLineSync()!); var result = n % 2 == 0 ? &q...
stackoverflow.com
댓글