[英]How can I respond to a prompt in Node.JS child process
我正在嘗試編寫一個程序,該程序以我的另一個用戶帳戶(管理員)身份運行一系列命令,但是我遇到了一個問題,其中“請輸入密碼”部分被完全跳過,填寫無緣無故地帶有隨機空格。
我如何 go 關於響應 Node.JS 子進程中的提示?
這是我的代碼:
var {spawn} = require("child_process");
var cmd = spawn("cmd.exe");
var sleep = t => new Promise(r => setTimeout(r, t * 1000));
cmd.on('close', code => interact({message: "Command executed."}));
// "interact" is a pop-up function, it'll be removed when testing is done, it functions as expected no issues.
cmd.stdout.on('data', text => console.log(Buffer.from(text).toString()));
cmd.stderr.on('data', text => console.log('Err:', Buffer.from(text).toString()));
cmd.stdin.write("runas /profile /user:Manxy \"cmd.exe\"\n");
await sleep(.2);
cmd.stdin.write("ThisIsThePassword\n");
await sleep(.2);
cmd.stdin.write("exit\n");
RUNAS 直接防止人們不安全地使用它,但是我可以將此文件包含在我的 package 中並改用它: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
例子; psexec.exe -u Manxy -p "ThisIsThePassword" cmd.exe
這對我來說大大簡化了它。
謝謝你, jsejcksn的鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.