gpt4 book ai didi

node.js - 直接使用批处理文件输出作为nodejs变量而不使用txt

转载 作者:行者123 更新时间:2023-12-04 13:08:05 25 4
gpt4 key购买 nike

我现在做的是使用批处理文件输出制作一个txt文件

@echo off
set fname=Logan
set lname=Anderson
set gender=male
echo %fname%>>1.txt
echo %lname%>>1.txt
echo %gender%>>1.txt

然后使用 nodejs 读取该 txt 并将其用作 nodejs 输入,但我想要的是如果可以使用批处理文件输出作为nodejs输入而不使用这个txt文件,直接调用"nodejs compiled project using pkg" exe file with variables from batch

例如,在批处理文件中

@echo off
set fname=Logan
set lname=Anderson
set gender=male
start "" "mycompiledproject.exe" "%fname%" "%lname%" "%gender%"

最佳答案

要在 Node 中使用命令行参数,您需要使用 process.argv(这里是它的文档:https://nodejs.org/docs/latest/api/process.html#process_process_argv)

因此在您的情况下,您的 node.js 代码应如下所示:

const process = require('process');

process.argv.forEach(function(value, index, array){
//value will be the argument(s), index is there position,
//and array is the entire array they are in. this function
//is called for each value.
});

一旦您将其转换为 exe,它应该可以在您的批处理中正常运行。

关于node.js - 直接使用批处理文件输出作为nodejs变量而不使用txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68441173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com