forked from hmenyus/node-calls-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpysearch.js
More file actions
48 lines (42 loc) · 1.39 KB
/
pysearch.js
File metadata and controls
48 lines (42 loc) · 1.39 KB
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
48
const path = require("path");
const fs = require('fs')
let pathenv = process.env.PATH.split(";");
let arg = process.argv[2];
for (let p of pathenv)
{
if (p.toLowerCase().includes("python"))
{
if (fs.existsSync(path.join(p, "python.exe")) || fs.existsSync(path.join(p, "python")))
{
if (arg == "lib")
{
fs.readdir(path.join(p, "libs"), function(err, items) {
let length = 0;
let result = "";
for (let i of items)
{
if (i.startsWith("python"))
{
if (i.endsWith(".lib") || i.endsWith(".a"))
{
if (length < i.length)
{
length = i.length;
result = i;
}
}
}
}
let index = result.lastIndexOf(".");
if (index != -1)
result = result.substring(0, index);
console.log("-l" + result);
});
}
else
console.log(path.join(p, arg));
return;
}
}
}
console.log("Cannot find PYTHON");