【问题标题】:Running a Python script with sudo in Vscode在 Vscode 中使用 sudo 运行 Python 脚本
【发布时间】:2017-12-22 15:13:11
【问题描述】:

我想知道(我是编程学生)如何在 VSCODE sudo 权限下运行,因为我必须运行测试的脚本需要它。它在 python 中。我还需要在其中运行一些参数('sniff')。我正在使用 linux。

【问题讨论】:

  • 文档中提到“如果您需要以提升(管理员)或不同权限运行 shell 命令,您可以在终端中使用平台实用程序,例如 runas.exe。” code.visualstudio.com/docs/editor/integrated-terminal#_windows
  • 我的错。我没有提到我在linux上......
  • 没关系。您的整个 python 脚本需要以root 权限运行,还是只需要在脚本中运行一些 命令(例如os.popen())?
  • 我在那里找到的。谢谢。他在运行时使用 ngrep 和嗅探参数。这不是我的,我想重构它并理解代码......我想我做到了。
  • 你找到了答案(怎么做)?如果是,您可以在下面的答案框中输入答案并接受:)

标签: linux python-3.x visual-studio-code


【解决方案1】:

我找到了部分答案。 // Linux "terminal.integrated.shellArgs.linux": ["-l"]设置中获得管理员权限。

Integrated Terminal - VSCode Docs

【讨论】:

    【解决方案2】:

    文档状态只使用设置为 true 的 sudo 属性。 https://code.visualstudio.com/docs/python/debugging

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal", 
                "sudo": true
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 2012-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多