Home > Back-end >  vscode input redirection not work properly
vscode input redirection not work properly

Time:10-18

I am using vscode.

I want to get input from input.txt when running python in vscode.

So I set launch.json like below. (added "args")

{
    "version": "0.2.0",
    "configurations": [
        {
            "args": [
                "<",
                "input.txt"
            ],
            "name": "Python: Curre545435nt File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
        }
    ]
}

(refer: https://code.visualstudio.com/docs/editor/debugging#_redirect-inputoutput-tofrom-the-debug-target)

Now when I run python, vscode sends a command like below.

c:; cd 'c:\Users\user\Desktop\ct'; & 
'C:\Users\user\miniconda3\python.exe' 
 'c:\Users\user\.vscode\extensions\ms-python.python-2021.9.1230869389\pythonFiles\lib\python\debugpy\launcher' 
  '13094 ' '--' 'c:\Users\user\Desktop\workingfolder\.vscode\launch.json' 
   '<' 'C:\Users\user\Desktop\workingfolder\input.txt'

The problem here is the ' on both sides of the <. ('<')

As a result of testing directly in the terminal, it was confirmed that it should be modified as shown below to run properly.

'python.exe' '<' 'input.txt' (not correct)

'python.exe' < 'input.txt' (correct)

What settings do I need to set in vscode to work properly?

CodePudding user response:

It seems not to work in the PowerShell for now, you can try switch to the cmd.

If you don't know how to switch the terminal type, you can refer to here.

  • Related