vscode input.txt, output.txt로 리다이렉션 안될때

이현준·2021년 9월 14일
1

문제 해결

목록 보기
1/1

[결론]setting.json에 추가로 해결

setting.json에

"terminal.integrated.automationShell.windows": "${env:windir}\\System32\\cmd.exe"

을 추가해주면 됩니다.

제 전체 setting.json 입니다.

{
    "workbench.colorTheme": "Default Dark+",
    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    "terminal.integrated.profiles.windows": {

        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "JavaScript Debug Terminal": {
            "extensionIdentifier": "ms-vscode.js-debug",
            "icon": "debug",
            "id": "extension.js-debug.debugTerminal",
            "title": "JavaScript Debug Terminal"
        }
    },
    "terminal.integrated.automationShell.windows": "${env:windir}\\System32\\cmd.exe",

}

"${env:windir}\\System32\\cmd.exe"값은 사용자마다 다를 수 있으므로 자신의 cmd 경로를 잘 찾아서 넣어주세요

아래는 문제 해결 과정입니다.

문제 해결 과정

고생의 시작

평소에 알고리즘 문제 풀때 입력을 복사 받아서 input.txt에 넣고 문제를 푸는데
갑자기 input.txt, output.txt로 리다이렉션 되던게 터미널로 나오는 문제를 만났다..
vscode의 설정이나 launch.json 부분도 건드린게 없어서 무슨 문제인가 한참 찾았는데
그 원인은

powershell이 문제였다.

python Debug Console이 실행될 때 PowerShell로 실행되는 것을 봤는데
cmd에서는 py test.py < input.txt로 하면 리다이렉션이 되지만
powershell에서는 리다이렉션이 안된다..
근데 이게 default 프로필을 cmd로 해도 python Debug Console에서는 죽어라 powershell로 실행되어서 힘들었다..
하여튼 python Debug Console을 powershell을 통해 실행하는게 아니라 cmd로 실행하면 되겠구나로 방향성을 잡았고 여러 설정을 시도해본 결과 setting.json에 "${env:windir}\\System32\\cmd.exe" 을 추가해서 해결해주었다.

launch.json

기존에 리다이렉션을 위한 launch.json 설정해둔 것

{
  // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
  // 기존 특성에 대한 설명을 보려면 가리킵니다.
  // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "args": ["<", "input.txt", ">", "output.txt"]
    },

  ]
}

1개의 댓글

comment-user-thumbnail
2022년 2월 9일

몇시간 동안 삽질하던거 덕분에 해결했어요! ㅠㅠ 감사한 마음에 회원가입해서 댓글남겨요~!ㅎㅎ

답글 달기