gpt4 book ai didi

linux - 在单个 session 中运行 VSCode 任务

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:12:32 28 4
gpt4 key购买 nike

我想将我的本地部署命令迁移到 VSCode 任务。我需要以 root 身份运行它们。当我在终端中执行这些操作时,我只被要求提供一次密码。

$ sudo echo hello                                                                                                                                                                                                                                                        
[sudo] password for pt12lol:
hello
$ sudo echo hello
hello

不幸的是,当我配置我的 VSCode 任务时:

{
"version": "2.0.0",
"tasks": [
{
"label": "Hello task",
"type": "shell",
"command": "sudo echo hello"
}
]
}

我想它在一个单独的 session 中运行每个任务,并且每次都要求我提供我的密码。

> Executing task: sudo echo hello <

[sudo] password for pt12lol:
hello

Terminal will be reused by tasks, press any key to close it.

> Executing task: sudo echo hello <

[sudo] password for pt12lol:
hello

Terminal will be reused by tasks, press any key to close it.

是否可以设置任务部署,以便它保留最后的 session 并且不要求我输入密码?

最佳答案

我也遇到了这个问题,this问题帮助了我。在 Linux 中,您不能显式地将密码传递给 sudo,但有一些方法可以解决这个问题。

回显密码 | sudo -S 命令

将使用 -S 参数将 password 传递给 sudo。来自sudo man page :

-S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.

修改您的代码在我的机器上产生了预期的效果。

{
{
"version": "2.0.0",
"tasks": [
{
"label": "Hello task",
"type": "shell",
"command": "echo password | sudo -S echo hello"
}
]
}

关于linux - 在单个 session 中运行 VSCode 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57304851/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com