我有一个 python Interactivity脚本,如下面的例子: $python sync_email.pyplease input your email: myemail@email.com validating...please input your password: password correct.Now will sync the email to local... 我想使用node来运
$python sync_email.py please input your email: myemail@email.com validating... please input your password: password correct. Now will sync the email to local...
我想使用node来运行python脚本,并自动输入电子邮件和密码.
实际上我想在无块IO中使用不同的电子邮件批量执行python脚本.怎么做?
你的问题的答案可能是Python-Shell,用npm安装.
https://www.npmjs.org/package/python-shell
要将数据发送到Python脚本(以stdin写入):
var PythonShell = require('python-shell'); var pyshell = new PythonShell('my_script.py'); // sends a message to the Python script via stdin pyshell.send('hello');
从Python脚本中获取(只需在python中使用print):
var PythonShell = require('python-shell'); var pyshell = new PythonShell('my_script.py'); pyshell.on('message', function (message) { // received a message sent from the Python script (a simple "print" statement) console.log(message); });
Verry易于使用,但请注意您可能会使用参数/脚本的路径,因此您必须像这样使用它.
var options = { mode: 'text', scriptPath: '/absolute/path/to/my/scripts', args: ['param1', 'value1', 'param2', 'value2'] }; var pyshell = new PythonShell('my_script.py',options);
也许它迟到了你的目的,但它可能会帮助别人,因为我有同样的问题,它花了我一些时间;)