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

비밀번호

댓글 작성자
 




... 181  182  183  184  185  186  187  188  189  [190]  191  192  193  194  195  ...
NoWriterDateCnt.TitleFile(s)
200정성태4/13/200618077.NET Framework: 58. 웹 서비스 메서드 호출 오류 유형 - text/html; charset=xxx, but expected 'text/xml'
199정성태4/13/200619432스크립트: 6. XHTML or HTML 4.01 표준 준수
194정성태4/13/200618672VC++: 22. IDL Library 절
193정성태4/13/200619163.NET Framework: 57. IComponentChangeService 인터페이스
192정성태6/1/200616435VC++: 21. Visual C++ struct와 class의 차이점
189정성태4/13/200624142VC++: 20. ActiveX CAB 파일 오류 유형 - 파일을 대상 디렉터리로 복사할 수 없음. [6]
187정성태11/24/200518460VS.NET IDE: 35. VS.NET 2005 IDE Tip - 2번째 : XML / XSL 지원 강화
186정성태11/23/200515971.NET Framework: 56. VS.NET 2005 IDE Tip
182정성태11/21/200516126.NET Framework: 55. 에러가 발생할 것만 같은 코드
181정성태11/20/200544908.NET Framework: 54. 한글이 포함된 ANSI, UTF-8, UNICODE 텍스트 파일 읽기 [3]파일 다운로드1
197정성태12/25/200520365    답변글 .NET Framework: 54.4. [관련 문제] A 태그의 href에서의 문제.
198정성태12/27/200518137    답변글 .NET Framework: 54.5. [추가]: VS.NET으로 UTF-8 홈페이지 구성하기
179정성태11/8/200515752.NET Framework: 53. .NET Remoting: 메시지 교체
178정성태11/5/200516654기타: 11. Dual Core 장만. ^^
177정성태11/2/200516380COM 개체 관련: 17. CoGetClassObjectFromURL파일 다운로드1
176정성태3/29/200621596.NET Framework: 52. covariance? [1]파일 다운로드1
175정성태10/31/200517194.NET Framework: 51. MSXML 6.0에서 디지털 서명 기능을 제거!
180정성태11/15/200517377    답변글 VS.NET IDE: 51.1. MSXML 6.0 정식 릴리스
174정성태10/31/200518139.NET Framework: 50. app.config 예시 [1]
173정성태10/30/200516956스크립트: 5. 스크립트 호출 관계
172정성태10/25/200525283.NET Framework: 49. ASP.NET 오류 유형 : 액세스가 거부되었습니다. [2]
171정성태11/14/200527111VC++: 19. 다국어 지원: setlocale( LC_TIME, "" ) 관련 [1]
170정성태11/14/200521774VS.NET IDE: 34. Visual SourceSafe 2005: Remote Internet Access over HTTP : 80 이외의 포트를 지정
206정성태2/1/200618092    답변글 VC++: 34.1. [추가]: Internet Access Plug-in 사용 시 유의 사항
168정성태11/14/200519082VS.NET IDE: 33. IIS 6.0 AppPool 설정 - Enable rapid-fail protection
169정성태10/14/200520777    답변글 VS.NET IDE: 33.1. Enable rapid-fail protection 상황 재현 방법
... 181  182  183  184  185  186  187  188  189  [190]  191  192  193  194  195  ...