DefinitelyTyped/python-shell/python-shell-tests.ts
Dolan 4ccd1312fa added python-shell typings (#13533)
* added python-shell typings

* added no implicit this to true

* added tslint fixes
2016-12-24 19:40:33 -05:00

38 lines
950 B
TypeScript

import * as ps from 'python-shell';
let PythonShell = ps.PythonShell;
ps.run('my_script.py', function (err) {
if (err) throw err;
console.log('finished');
});
var options = {
mode: 'text',
pythonPath: 'path/to/python',
pythonOptions: ['-u'],
scriptPath: 'path/to/my/scripts',
args: ['value1', 'value2', 'value3']
};
ps.run('my_script.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});
var pyshell = new PythonShell('my_script.py');
// sends a message to the Python script via stdin
pyshell.send('hello');
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
});
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err) throw err;
console.log('finished');
});