Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

Visual Studio Code에서 콘솔 응용 프로그램 개발 시 "입력"받는 방법

예를 들어 다음과 같이 입력을 받는 콘솔 프로그램을 만든 경우,

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");

        Console.ReadLine();
    }
}

Visual Studio Code에서 실행하면 "입력"을 받을 수 없습니다. 물론 필요가 없다면 그냥 종료해도 되겠지만 그렇지 않은 경우라면 문제가 되는데요, 이에 대해서는 관련 옵션을 설정할 수 있는 다음의 공식 문서에 해답이 있습니다.

Configuring launch.json for C# debugging - Console (terminal) window
; https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window

Debug Console window cannot accept Console.ReadLine() input during debugging
; https://github.com/OmniSharp/omnisharp-vscode/issues/1053

그러니까, ".vscode/launch.json" 파일을 보면 기본적으로 "console" 설정이 입력을 받을 수 없는 "internalConsole"로 되어 있습니다.

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/vscode_console_input.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

이 값을 "integratedTerminal" 또는 "externalTerminal"로 바꿔주면 입력 값을 받을 수 있는데요. "externalTerminal"의 경우 실행 시 Visual Studio Code의 하단 "OUTPUT" 뷰가 사용되지 않고 아예 콘솔 창이 하나 뜨게 됩니다.

vscode_console_input_1.png

새 창이 하나 뜨는 게 왠지 거슬릴 수 있는데, 그런 경우라면 "integratedTerminal" 옵션을 선택하면 됩니다.




참고로 "Remote Development" 환경의 경우,

로컬의 Visual Studio Code로 원격 리눅스 머신에 접속해 개발하는 방법
; https://www.sysnet.pe.kr/2/0/11942

윈도우에서 리눅스로 접근하고 있다면, "externalTerminal" 설정은 다음과 같은 식의 오류가 발생하게 됩니다.

Unable to launch debugger worker process (vsdbg) through the terminal. can't find terminal application 'xterm'

xterm을 설치해 주면,

[Centos 7]

$sudo yum install xterm

이제는 다음과 같이 바뀝니다.

Unable to launch debugger worker process (vsdbg) through the terminal. xterm: Xt error: Can't open display: 

저도 해보진 않았는데 아마도 필요한 설정을 해주면,

Windows 10에서 리눅스용 프로그램 설치하고 실행하기
; https://medium.com/rkttu/windows-10%EC%97%90%EC%84%9C-%EB%A6%AC%EB%88%85%EC%8A%A4%EC%9A%A9-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8-%EC%84%A4%EC%B9%98%ED%95%98%EA%B3%A0-%EC%8B%A4%ED%96%89%ED%95%98%EA%B8%B0-2cb0d7892d12

Xming X Server for Windows
; http://sourceforge.net/projects/xming/

"externalTerminal" 설정이 동작해 새 창으로 뜨게 될 것입니다. 하지만, "integratedTerminal" 옵션이 제공되므로 저렇게까지 할 필요는 없는 것 같습니다. "integratedTerminal" 옵션이 한 가지 불편한 점이 있다면, 그 모드로 띄웠을 때 예외가 발생해 콘솔 프로그램이 종료되면 "OUTPUT" 창이 더 이상 동작하지 않게 되는 문제가 발생한다는 점입니다. 이럴 때는 OUTPUT 창을 닫고 다시 열어야 하는 식으로 조정을 좀 해야 합니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/5/2019]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 166  167  168  169  170  171  172  173  174  175  176  177  [178]  179  180  ...
NoWriterDateCnt.TitleFile(s)
587정성태6/10/200828703VS.NET IDE: 56. C#에서 아쉬운 __DATE__, __TIME__ 매크로 [2]
586정성태6/4/200826346오류 유형: 56. WPF 디자이너 - The string was not recognized as a valid DateTime [2]
585정성태6/4/200834610.NET Framework: 101. WPF - ActiveX 컨트롤 호스팅하는 방법 [2]
582정성태5/16/200826372오류 유형: 55. Windowless ActiveX controls are not supported
580정성태4/24/200825425VC++: 34. 64비트 윈도우즈에서의 이벤트 후킹
579정성태4/24/200825255VC++: 33. 변환 후의 RGS 파일 내용을 얻는 방법
577정성태4/16/200826184.NET Framework: 100. XML Serializer를 이용한 값 복사 [5]
575정성태4/7/200823375오류 유형: 54. TFS Source Control - 명령을 사용할 수 없음 [2]
574정성태3/31/200821486오류 유형: 53. TFS 연결 오류 - The workspace [...] exists on computer [...]
573정성태3/25/200825531Windows: 31. TS Web Access와 UAC [1]
570정성태3/17/200824670오류 유형: 52. TFS 연결 오류 - TF31001 [2]
569정성태3/16/200825829Team Foundation Server: 24. TFS 2008로 마이그레이션 (2) [2]
566정성태2/28/200826963.NET Framework: 99. AppDomain.GetEntryAssembly()를 우회하는 방법파일 다운로드1
564정성태2/16/200826589Windows: 30. TS Web Access + Vista SP1 [2]
563정성태2/16/200825950오류 유형: 51. Vista(UAC) + 웹 프로젝트 디버깅: System.UnauthorizedAccessException
562정성태2/12/200830194Windows: 29. Windows Server 2008 설치 [4]
561정성태1/10/200823915오류 유형: 50. IE 7 + 잘못된 HTC 파일 경로 = File not found [5]
559정성태1/1/200828719Windows: 28. Vista에서 끌어다 놓기로 GAC 등록하는 방법 [2]
558정성태1/1/200845900개발 환경 구성: 33. 32bit/64bit OLE DB Provider [1]
557정성태12/22/200724234개발 환경 구성: 32. WSCF와 VS.NET 2008
556정성태12/16/200722332기타: 22. 인기 순위 정리 : 조회수 1000 회 이상
555정성태12/16/200725312기타: 21. 인기 순위 정리 : 조회수 500 ~ 999회 글 목록
554정성태12/16/200729689기타: 20. 인기 순위 정리 : 조회수 250 ~ 499회 글 목록
553정성태12/16/200730068기타: 19. 인기 순위 정리 : 조회수 100 ~ 249회 글 목록
552정성태12/16/200723678기타: 18. 인기 순위 정리 : 조회수 000 ~ 099 회 글 목록
550정성태12/16/200722912Team Foundation Server: 23. TFS 2005에서 TFS 2008로 마이그레이션 [2]
... 166  167  168  169  170  171  172  173  174  175  176  177  [178]  179  180  ...