forked from hunmer/VideoManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuntil.js
More file actions
37 lines (32 loc) · 1012 Bytes
/
until.js
File metadata and controls
37 lines (32 loc) · 1012 Bytes
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
var spawn = require("child_process").spawn;
function runCmd(cmd, callback, onClose) {
console.log(cmd);
return new Promise(function(resolve, reject) {
var result = spawn('cmd.exe ', ['/s', '/c', cmd], { shell: true });
result.on('close', function(code) {
if (typeof(onClose) == 'function') onClose(code);
});
result.stdout.on('data', function(data) {
callback(iconvLite.decode(data, 'cp936'));
});
resolve();
});
}
function replaceAll_once(str, search, replace, start = 0) {
while (true) {
var i = str.indexOf(search, start);
if (i == -1) break;
start = i + search.length;
str = str.substr(0, i) + replace + str.substr(start, str.length - start);
start += replace.length - search.length;
}
return str;
}
function getPath(p) {
return replaceAll_once(p, '*path*', replaceAll_once(__dirname, '\\', '\/'));
}
module.exports = {
runCmd,
getPath,
replaceAll_once
}