Visual studio code VSCode任务将命令包装在'';在多行命令中使用引号分隔参数
我正在尝试创建一个VSCode任务,该任务运行一个带有一些参数的命令Visual studio code VSCode任务将命令包装在'';在多行命令中使用引号分隔参数,visual-studio-code,task,Visual Studio Code,Task,我正在尝试创建一个VSCode任务,该任务运行一个带有一些参数的命令 "tasks": [ { "label": "Execute in Max", "type": "shell", "command": "cd\\; C:\\MXSPyCOM.exe", "args": [ "-f", "'${file}'" ], "problemMatche
"tasks": [
{
"label": "Execute in Max",
"type": "shell",
"command": "cd\\; C:\\MXSPyCOM.exe",
"args": [
"-f",
"'${file}'"
],
"problemMatcher": []
}
]
从中我得到了错误:
&:无法加载模块“cd”。有关详细信息,请运行“导入模块cd”。
第1行字符数:3
+&“cd”;C:\MXSPyCOM.exe'-f'C:\Users\。。。
+ ~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo:ObjectNotFound:(cd\;C:\MXSPyCOM.exe:String)[],CommandNotFoundException
+FullyQualifiedErrorId:无法自动加载模块
我相当确定问题在于它试图执行的命令:'cd\;C:\MXSPyCOM.exe'-f'C:\Users\
出于某种原因,主命令块被用单引号括起来,这使得shell认为它是一个命令,而不是多个命令
这种情况过去并不经常发生,几个月前,当我最后一次使用它时,我的这个确切的命令工作得很好。知道有什么问题吗?是的,直到1.21.0版本,vscode才在args中有空格时发出警告,最新版本在args中有空格时使用单引号包装命令和args。 只需通过以下方式中断命令,使其中没有空格
"command": "cd\\;C:\\MXSPyCOM.exe",
或
如果没有这样的选项(例如向ssh会话传递命令),我要做的是:
"command": "ssh",
"args": [
"host_name",
"bash",
"-c",
"'\"",
"cd /some_dir;",
...
"\"'"
],
快速而肮脏的解决方法是根本不使用args
字段,而是在command
中使用完整的命令
另一个解决方案是编写您自己的脚本,然后从tasks.json调用它们。如果我注释掉args,shell就会执行得很好。我还可以通过标准的cmd或PS控制台运行带有args的exe,没有问题
"command": "ssh",
"args": [
"host_name",
"bash",
"-c",
"'\"",
"cd /some_dir;",
...
"\"'"
],