python-shell
python-shell copied to clipboard
Can we return the result from python-shell ?
Here is my code in node.js file
function emailVerification(ordernumber,orderdate,key){ console.log(ordernumber); var options = { mode: 'text', args: ['id','pwd,ordernumber,'passkey',orderdate,key] }; let pyshell = PythonShell.run('email_check_driver.py', options, function (err,res) { console.log("Result",res) if (err) throw err; console.log('finished'); return res #######( Can i return the result like this?) }); pyshell.on('message', function (message) { // received a message sent from the Python script (a simple "print" statement) console.log('Message',message); return message ####### ( Or Can i return the result like this?) }); }
I want to fetch data here in the variable when calling the function. Is it Possible?
var json_data = emailVerification('9HPDCHKA36','May 28, 2021, 2:51:51 PM','Order Request') console.log("json",json_data)
You'd do something like this I guess
const options = {
mode: "text",
};
const pyshell = new PythonShell("email_check_driver.py", options);
function emailVerification(ordernumber, orderdate, key) {
console.log(ordernumber);
let Result;
pyshell.send(ordernumber);
pyshell.on("message", function (message) {
// received a message sent from the Python script (a simple "print" statement)
Result = message;
});
return Result;
}
Thank you. I will try
On Sun, 6 Jun, 2021, 11:19 AM Shivam, @.***> wrote:
You'd do something like this I guess
const options = { mode: "text",};const pyshell = new PythonShell("email_check_driver.py", options); function emailVerification(ordernumber, orderdate, key) { console.log(ordernumber); let Result; pyshell.send(ordernumber); pyshell.on("message", function (message) { // received a message sent from the Python script (a simple "print" statement) Result = message; }); return Result;}
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/extrabacon/python-shell/issues/244#issuecomment-855343231, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMBUMCRF3SBSMMS5JH6YITTRMD63ANCNFSM452TSZEA .
You'd do something like this I guess
const options = { mode: "text", }; const pyshell = new PythonShell("email_check_driver.py", options); function emailVerification(ordernumber, orderdate, key) { console.log(ordernumber); let Result; pyshell.send(ordernumber); pyshell.on("message", function (message) { // received a message sent from the Python script (a simple "print" statement) Result = message; }); return Result; }
This doesn't work with 'pythonError'
Are there any updates on this?