VSCode 的launch.json 中的args 和runtimeArgs 有什么区别? [英] What is the difference between args and runtimeArgs in VSCode's launch.json?

查看:60
本文介绍了VSCode 的launch.json 中的args 和runtimeArgs 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

launch.json 中的 argsruntimeArgs 有什么区别?

What is the difference between args and runtimeArgs in launch.json?

// Optional arguments passed to the runtime executable
"runtimeArgs": []
// Command line arguments passed to the program
"args": []

程序与运行时可执行文件不是一回事吗?

Is the program not the same thing as the runtime executable?

问题背后的额外信息和动机:

我正在开发一个 nodejs 应用程序.在我的 package.json 中,我有一个 start 脚本:

I am developing a nodejs application. In my package.json, I have a start script:

"start": "electron ./src/Main/main.js arg2",在我的应用程序代码中,我访问了 process.argv[2]让我 arg2,所以当我运行 npm start 时,我的应用程序按预期工作.

"start": "electron ./src/Main/main.js arg2", and in my app code, I access process.argv[2] which gets me arg2, so when I run npm start, my app works as intended.

当我从 VSCode 运行应用程序时,它没有,原因是我没有在 launch.json 中提供任何额外的参数.我应该把这些论点放在哪里?process.argv 似乎包含在 argsruntimeArgs 中提供的参数,尽管它也包含在一些 --debug-brk 参数,这是我不想要的.

When I run the app from VSCode, however it doesn't, and the reason was that I wasn't supplying any additional arguments in launch.json. Where should I put those arguments? process.argv seems to contains the arguments provided in either args or runtimeArgs though it also sticks in some --debug-brk argument, which I don't want.

当我从命令行 (npm start) 运行应用程序或从 VSCode 启动它时,我希望能够一致地使用 process.argv.

I want to be able to use process.argv consistently when I run the app from the command line (npm start) or start it from VSCode.

推荐答案

我认为这主要在 节点调试文档:

您可以直接从启动配置中使用npm"脚本或其他任务运行器工具,而不是直接使用 node 启动 Node.js 程序:

Instead of launching the Node.js program directly with node, you can use 'npm' scripts or other task runner tools directly from a launch configuration:

  • PATH 上可用的任何程序(例如npm"、mocha"、gulp"等)均可用于 runtimeExecutable 属性 [...]

runtimeExecutable 不是你要调试的程序,而是用来运行它的可执行文件. 所以看起来 runtimeArgs 是为了 runtimeExecutable as args 用于program.

runtimeExecutable is not the program you want to debug, but the executable used to run it. So it appears that runtimeArgs is to runtimeExecutable as args is to program.

如果您对它的详细工作方式感兴趣,这里是 debugAdapter.ts 实现的相关部分.

If you're interested in how it works in detail, here's the relevant part of the debugAdapter.ts implementation.

这篇关于VSCode 的launch.json 中的args 和runtimeArgs 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆