-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
42 lines (36 loc) · 1.22 KB
/
server.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
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
function analyzeCode(filePath) {
return new Promise((resolve, reject) => {
// Pass the file path as an argument to the Python script
const pythonProcess = spawn('python', [path.join(__dirname, 'test.py'), filePath]);
let output = '';
pythonProcess.stdout.on('data', (data) => {
output += data.toString();
});
pythonProcess.stderr.on('data', (data) => {
console.error(`Python stderr: ${data}`);
});
pythonProcess.on('close', (code) => {
if (code === 0) {
console.log('Report generated and saved'); // Add console.log statement here
resolve(output);
} else {
reject(new Error(`Python script exited with code ${code}`));
}
});
});
}
if (require.main === module) {
const filePath = process.argv[2];
if (!filePath) {
console.error('Please provide a file path as an argument');
process.exit(1);
}
analyzeCode(filePath).then((output) => {
console.log(output);
}).catch((err) => {
console.error(err);
});
}