|
1 | 1 | import {EventEmitter} from 'events'; |
2 | | -import { ChildProcess,spawn, SpawnOptions, exec } from 'child_process'; |
| 2 | +import { ChildProcess,spawn, SpawnOptions, exec, execSync } from 'child_process'; |
3 | 3 | import {EOL as newline, tmpdir} from 'os'; |
4 | 4 | import {join, sep} from 'path' |
5 | 5 | import {Readable,Writable} from 'stream' |
6 | 6 | import { writeFile, writeFileSync } from 'fs'; |
| 7 | +import { promisify } from 'util'; |
7 | 8 |
|
8 | 9 | function toArray<T>(source?:T|T[]):T[] { |
9 | 10 | if (typeof source === 'undefined' || source === null) { |
@@ -283,6 +284,16 @@ export class PythonShell extends EventEmitter{ |
283 | 284 | return PythonShell.run(filePath, options, callback); |
284 | 285 | }; |
285 | 286 |
|
| 287 | + static getVersion(pythonPath?:string){ |
| 288 | + if(!pythonPath) pythonPath == this.defaultPythonPath |
| 289 | + let execPromise = promisify(exec) |
| 290 | + return execPromise(pythonPath + " --version") |
| 291 | + } |
| 292 | + |
| 293 | + static getVersionSync(pythonPath?:string){ |
| 294 | + return execSync(pythonPath + " --version").toString() |
| 295 | + } |
| 296 | + |
286 | 297 | /** |
287 | 298 | * Parses an error thrown from the Python process through stderr |
288 | 299 | * @param {string|Buffer} data The stderr contents to parse |
|
0 commit comments