【问题标题】:vscode input redirection not work properlyvscode 输入重定向无法正常工作
【发布时间】:2021-11-13 16:16:36
【问题描述】:

我正在使用 vscode。

我想在 vscode 中运行 python 时从 input.txt 中获取输入。

所以我像下面这样设置了 launch.json。 (添加“参数”)

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

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

现在当我运行 python 时,vscode 会发送如下命令。

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'

这里的问题是 '')

由于直接在终端测试,确认应该修改如下图才能正常运行。

'python.exe' '&lt;' 'input.txt' (not correct)

'python.exe' &lt; 'input.txt' (correct)

我需要在 vscode 中设置哪些设置才能正常工作?

【问题讨论】:

    标签: python redirect visual-studio-code input


    【解决方案1】:

    目前在 PowerShell 中似乎无法使用,您可以尝试切换到 cmd

    如果不知道如何切换终端类型,可以参考here

    【讨论】:

    • 完美!!非常感谢:)
    猜你喜欢
    • 2017-09-23
    • 2015-08-09
    • 2014-07-01
    • 2015-12-21
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多