-
Notifications
You must be signed in to change notification settings - Fork 0
/
sh.js
47 lines (42 loc) · 1.32 KB
/
sh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var child_process_1 = require("child_process");
console.log('Hello, TypeScript!');
// 创建 rclone 命令的子进程
var rclone = (0, child_process_1.spawn)('rclone', ['config']);
// 定义变量来控制输入的值
var inputValue = 'n';
// 监听子进程的 stdout 输出
rclone.stdout.on('data', function (data) {
// 将子进程的输出转换成字符串
var output = data.toString();
// 在控制台中打印输出
console.log(output);
// 如果输出中包含 'y/n',则向子进程输入 'n'
if (output.includes('y/n')) {
rclone.stdin.write(inputValue.concat('\n'));
}
});
// // 监听子进程的 stderr 输出
// rclone.stderr.on('data', function (data) {
// // 将子进程的错误输出转换成字符串
// var error = data.toString();
// // 在控制台中打印错误输出
// console.error(error);
// });
setTimeout(() => {
rclone.stdin.write('n\n');
}, 2000);
setTimeout(() => {
rclone.stdin.write('31\n');
}, 2000);
setTimeout(() => {
rclone.stdin.write('32\n');
}, 2000);
setTimeout(() => {
rclone.stdin.write('31\n');
}, 2000);
// 监听子进程的退出事件
rclone.on('exit', function (code) {
console.log("rclone exited with code ".concat(code));
});