如何将参数传递给nodemon(或node-supervisor)中的可执行文件?

发布于 2024-12-26 21:55:38 字数 2078 浏览 3 评论 0 原文

节点可以使用这样的调试参数运行

$ node --debug src/file.js

我也可以通过咖啡脚本二进制文件传递该参数,如下所示,

$ coffee --nodejs --debug src/file.coffee

这可以工作。但当我涉及 supervisor 时,事情会变得更加困难。运行咖啡脚本没问题:

$ supervisor -w src src/file.coffee

但我想调试与 supervisor。如何通过 supervisor 发送诸如 --debug 之类的参数?我尝试将可执行文件设置为带有如下参数的字符串:

$ supervisor -w src -x "coffee --nodejs --debug" src/server.coffee

这产生了无限重复的错误消息:

DEBUG:使用“coffee --nodejs --debug src/server.coffee”启动子进程
调试:execvp():没有这样的文件或目录

这很奇怪,因为在终端中运行 coffee --nodejs --debug src/server.coffee 是有效的。

那么我如何通过 supervisor 发送参数?


编辑:我想扩展我的问题,并提到我现在已经尝试使用 nodemon 也是如此。似乎 nodemon 被认为优于 node-supervisor,所以我会接受任何解释如何在通过 --debug 传递给节点进程的答案href="https://github.com/remy/nodemon" rel="noreferrer">nodemon


编辑: 这是 nodemon。显然,参数传递的顺序不同:-(

$ nodemon -w src -x coffee --nodejs --debug src/server.coffee
15 Jan 03:41:56 - [nodemon] v0.6.5
15 Jan 03:41:56 - [nodemon] watching: /foo/bar/server/src
15 Jan 03:41:56 - [nodemon] running --debug
15 Jan 03:41:56 - [nodemon] starting `coffee --debug --nodejs src/server.coffee`

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^

Error: unrecognized option: --debug

node can be run with a debug parameter like this

$ node --debug src/file.js

I can also pass that parameter through the coffee-script binary like this

$ coffee --nodejs --debug src/file.coffee

Which works. But things get more difficult when I involve supervisor. Running coffee scripts is no problem:

$ supervisor -w src src/file.coffee

But I want to debug the coffee scripts that I'm running with supervisor. How can I send arguments such as --debug through supervisor? I tried setting the executable to a string with the arguments like this:

$ supervisor -w src -x "coffee --nodejs --debug" src/server.coffee

Which produced an infinitely repeating error message saying

DEBUG: Starting child process with 'coffee --nodejs --debug src/server.coffee'
DEBUG: execvp(): No such file or directory

Which is odd, because running coffee --nodejs --debug src/server.coffee in the terminal works.

So how can I send arguments through supervisor?


Edit: I want to expand my question with mentioning that I've now tried using nodemon as well. It seems nodemon is considered preferable to node-supervisor, so I'll accept any answer that explains how to pass --debug to the node process when launching coffee scripts through nodemon


Edit: Here's the output from nodemon. Clearly the arguments are not passed in the same order :-(

$ nodemon -w src -x coffee --nodejs --debug src/server.coffee
15 Jan 03:41:56 - [nodemon] v0.6.5
15 Jan 03:41:56 - [nodemon] watching: /foo/bar/server/src
15 Jan 03:41:56 - [nodemon] running --debug
15 Jan 03:41:56 - [nodemon] starting `coffee --debug --nodejs src/server.coffee`

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^

Error: unrecognized option: --debug

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无需解释 2025-01-02 21:55:38

实际上,它被证明是一个错误:)

简短的方法:

nodemon --debug -w src src/server.coffee

或者(其中 --nodejs 和 --debug 作为 exec 包含在内)

nodemon -x "coffee --nodejs --debug" -w src src/server.coffee

或者(看起来比上面更好)

nodemon -x coffee --nodejs --debug -w src src/server.coffee

(全部在 nodemon 0.6.6 上)

actually, it turned out to be a bug :)

The short way:

nodemon --debug -w src src/server.coffee

Or (where --nodejs and --debug are included as the exec)

nodemon -x "coffee --nodejs --debug" -w src src/server.coffee

Or (looks nicer than above)

nodemon -x coffee --nodejs --debug -w src src/server.coffee

(all on nodemon 0.6.6)

只是一片海 2025-01-02 21:55:38

您可以将 -- 与主管一起使用。不确定这是否适用于 -x 语法:

supervisor -w src -- Coffee.js --nodejs --debug src/server.coffee

You can use -- with supervisor. Not sure if this would work with the -x syntax though:

supervisor -w src -- coffee.js --nodejs --debug src/server.coffee

一杆小烟枪 2025-01-02 21:55:38

从对 Supervisor 的快速回顾来看,它似乎将所有参数作为参数传递给脚本本身,因此您需要使用 nodemon。

Nodemon 挑选出它自己的参数,否则它们会传递给 Node。在当前版本中,js/coffee 文件后面的参数被保留,而 JS 文件之前的参数的顺序颠倒了,所以试试这个。

nodemon -w src -x coffee --debug --nodejs src/server.coffee

当然,看来你也注意到了:P
https://github.com/remy/nodemon/issues/54

所以是的,排序问题是一个错误,希望能够得到修复。

From a quick review of supervisor, it look like it passes all arguments as arguments to the script itself, so you'll want to use nodemon.

Nodemon picks out it's own arguments, but otherwise they are passed to node. In the current version, arguments after the js/coffee file are preserved, and arguments before the JS file have their order inverted, so try this.

nodemon -w src -x coffee --debug --nodejs src/server.coffee

Of course, it looks like you noticed that too :P
https://github.com/remy/nodemon/issues/54

So yeah, the ordering issue is a bug that hopefully will get fixed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文