【发布时间】:2019-05-17 01:56:43
【问题描述】:
我有这样的文件结构:
bots -|
|- test1 -|
|- index.js
|- activate.bat
|- token.txt
|- test2 -|
|- index.js
|- actiate.js
|- token.txt
|- run_all.bat
index.js 是使用node 命令在 NodeJS 中运行的文件。两个index.js 文件都需要一个存储在token.txt 文件中的密钥。 index.js文件读取文本文件
activate.bat 就是这样:
@echo off
node index.js
但是我想同时运行这两个文件,并且只启动一个 .bat 文件,这就是 run_all.bat 的用武之地。
我尝试像在activate.bat 中那样运行每个文件,所以:
@echo off
echo Starting all bots...
start /b node test1\index.js
start /b node test2\index.js
但是我得到一个错误:
PS C:\Users\Simon\Desktop\bot> ./run_all.bat
Starting all bots...
PS C:\Users\Simon\Desktop\bot> test1 running
test2 running
(node:10176) UnhandledPromiseRejectionWarning: Error: An invalid token was provided.
at Promise (C:\Users\Simon\node_modules\discord.js\src\client\rest\RESTMethods.js:34:54)
at new Promise (<anonymous>)
at RESTMethods.login (C:\Users\Simon\node_modules\discord.js\src\client\rest\RESTMethods.js:33:12)
at Client.login (C:\Users\Simon\node_modules\discord.js\src\client\Client.js:279:30)
at ReadFileContext.callback (C:\Users\Simon\Desktop\bot\test1\index1.1.js:88:12)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:235:13)
(node:4836) UnhandledPromiseRejectionWarning: Error: An invalid token was provided.
at Promise (C:\Users\Simon\node_modules\discord.js\src\client\rest\RESTMethods.js:34:54)
at new Promise (<anonymous>)
at RESTMethods.login (C:\Users\Simon\node_modules\discord.js\src\client\rest\RESTMethods.js:33:12)
at Client.login (C:\Users\Simon\node_modules\discord.js\src\client\Client.js:279:30)
at ReadFileContext.callback (C:\Users\Simon\Desktop\bot\test2\index.js:65:12)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:235:13)
(node:10176) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:4836) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:10176) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:4836) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
单独运行每个activate.bat 时,我没有收到此错误,这是怎么回事?我的批处理命令是否以某种方式混淆了不同的 token.txt 文件
【问题讨论】:
-
我真的觉得这个应该留作答案,太完整了,我现在没法测试。 @Mofi
标签: node.js batch-file batch-processing