nodemon在cmd中但不在批处理文件中工作的原因是什么? [英] What is the reason for nodemon working in cmd but not in a batch file?

查看:310
本文介绍了nodemon在cmd中但不在批处理文件中工作的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制造一个不和谐的机器人.我为机器人编写的所有代码都可以运行,除了应该运行它的批处理文件之外.最初我只是使用node命令,当我打开cmd,导航到该文件夹​​并手动键入它时,它工作正常,但是当我将相同的代码放入批处理文件中时,出现了此错误:

I am in the process of making a discord bot. All of the code that I have written for the bot works except for the batch file that is supposed to run it. Originally I was just using the node command and when I opened cmd, navigated to the folder, and typed it manually it worked fine, but when I put that same code into a batch file it gave me this error:

节点"未被识别为内部或外部命令,可操作程序或批处理文件.

'node' is not recognized as an internal or external command, operable program or batch file.

这是该批处理文件的所有代码:

This is all the code for that batch file:

@echo off
node bot.js
pause

node命令在我的路径中,所以我不确定为什么它不起作用,但是在另一条帖子中,有人建议不要直接键入node来键入完整的文件路径,所以我尝试了这一点,并且行得通.

The node command was in my path so I'm not sure why it wasn't working, but in another post, someone recommended that instead of typing just node to type the full file path, so I tried this and it worked.

这是新的工作代码:

@echo off
"C:\Program Files\nodejs\node.exe" bot.js
pause

然后我安装了 nodemon .同样,当我导航到该文件夹​​并手动键入该文件时,该命令也可以在cmd中使用,但是当我尝试在批处理文件中执行该操作时,它将不起作用.与其给我错误,不如立即关闭窗口之前的错误.这是代码:

Then I installed nodemon. Again this works in the cmd when I navigated to the folder and typed it manually, but when I try to do it in the batch file it does not work. Instead of giving me the error it had been before the window just instantly closes. Here is that code:

@echo off
nodemon bot.js
pause

由于我在代码末尾有暂停命令,因此如果出现错误,它应该在此停下来,但是由于某种原因,它在到达那里之前就已经关闭了. nodemon命令在我的路径中,我也尝试过用文件路径C:\Users\tdkni\AppData\Roaming\npm\nodemon.cmd替换nodemon,就像上一篇文章中推荐的那样.这些解决方案都不起作用,我认为这是因为除了未检测到nodemon命令之外,还有其他问题.我没有看到任何错误消息,因为它会立即关闭,所以我不知道到底是什么问题.

Since I have the pause command at the end of the code it should stop there if I get an error, but it is closing before it gets there for some reason. The nodemon command is in my path and I have also tried replacing nodemon with the file path, C:\Users\tdkni\AppData\Roaming\npm\nodemon.cmd, like I was recommended in the previous post. Neither of these solutions worked, and I think that is because there is some other problem besides the nodemon command not being detected. I don't see any error message since it is closing instantly so I don't know exactly what is wrong.

根据同时删除的注释中的建议,文件扩展名.bat.cmd的注册如下.

The registration of the file extensions .bat and .cmd is as follows according to an advice in a comment deleted in the meantime.

推荐答案

我要感谢你们所有人试图帮助我解决我遇到的这个问题.大家都很乐于助人,虽然它可能无法解决我的问题,但确实帮助我了解了所有这些工作原理.我只是尝试使用我创建的批处理文件来启动该机器人,但它突然起作用了.我不知道为什么,因为我尝试以与整个时间相同的方式启动它,但是据我所知,没有其他人遇到这个问题,所以我可能对此并不重要不知道是什么解决了.再次感谢所有为我提供帮助的人.

I'd like to thank all of you for trying to help me with this problem I was having. You have all been very helpful, and while it may not have fixed my problem it did help me understand how all of this works. I just tried to start the bot using the batch file I made and it suddenly worked. I don't know why because I tried to start it the same way I had been the entire time, but as far as I could find, no one else was having this issue anyways so it probably won't matter much that I don't know what fixed it. Again, thank you to everyone that helped me with this.

这篇关于nodemon在cmd中但不在批处理文件中工作的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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