You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Node.js生成独立终端运行Ashita-cli并完成游戏启动流程?

解决方案

核心思路

直接调用Windows原生终端(cmd.exe 或 PowerShell),通过终端执行 ashita-cli.exe,同时配置终端在命令执行后保持窗口,确保用户能继续输入账号密码。避免嵌套调用 Start-Process 带来的参数转义和进程生命周期问题。

可行代码实现

方案1:使用CMD终端(无权限弹窗)

const { spawn } = require('child_process');
const { join } = require('path');

const ASHITA_LOCATION = '你的Ashita安装绝对路径';
const scriptName = '你的脚本文件名';

// 构造完整执行命令
const ashitaCmd = `"${join(ASHITA_LOCATION, 'ashita-cli.exe')}" "managed/${scriptName}.ini"`;

// 启动CMD,/k 参数保证命令执行后窗口不关闭
const proc = spawn('cmd.exe', ['/k', ashitaCmd], {
  detached: true,
  windowsHide: false,
  stdio: 'inherit' // 让终端直接接收用户输入输出
});

proc.unref(); // Node.js父进程可独立退出,不影响终端窗口

方案2:使用PowerShell终端(带管理员权限)

如果必须以管理员身份运行,可通过以下方式保持窗口并支持输入:

const { spawn } = require('child_process');
const { join } = require('path');

const ASHITA_LOCATION = '你的Ashita安装绝对路径';
const scriptName = '你的脚本文件名';

const ashitaPath = join(ASHITA_LOCATION, 'ashita-cli.exe');
// 执行ashita-cli后等待进程结束,再提示用户关闭窗口
const psCmd = `Start-Process -FilePath "${ashitaPath}" -ArgumentList "managed/${scriptName}.ini" -Wait; Read-Host '操作完成,按回车关闭窗口'`;

const proc = spawn('powershell.exe', ['-NoExit', '-Command', psCmd], {
  detached: true,
  windowsHide: false,
  stdio: 'inherit'
});

proc.unref();

问题根源分析

之前的代码存在两个致命问题:

  1. 参数转义错误:使用HTML转义符 " 替代原生引号,导致PowerShell无法正确解析路径和参数。
  2. 窗口生命周期未配置:未添加终端保持窗口的逻辑,ashita-cli.exe 退出后终端直接关闭,无法进行账号密码输入。

关键注意事项

  • 必须使用绝对路径配置 ASHITA_LOCATION,避免相对路径导致的文件找不到问题。
  • stdio: 'inherit' 是核心配置,它让终端窗口直接关联用户的输入输出流,确保能接收账号密码输入。
  • 无需管理员权限时优先选方案1,避免权限弹窗干扰流程。

内容的提问来源于stack exchange,提问作者Christopher Trent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 18:22:46