发布时间:2019-09-27 07:09:51编辑:auto阅读(2226)
【PyExecJS】
#encoding: utf-8
#author: walker
# date: 2019-03-13
# summary: 利用 PyExecJS 调用 js 函数
import execjs
JSCode = r'''
function add(x, y) {
return x + y;
}
'''
CTX = execjs.compile(JSCode)
def test():
# 直接使用
print(execjs.get().eval('3+2'))
# 调函数使用
print(CTX.call('add', 3, 6))
if __name__ == '__main__':
test()【Node.js】
#encoding: utf-8
#author: walker
# date: 2019-03-13
# summary: 直接用 Node.js 调用 js 函数
from subprocess import check_output
def test():
# 直接调用
bytesTxt = check_output('node -e console.log(3+2)', timeout=100)
print(bytesTxt.decode('utf8').strip())
# 用 node 直接执行 js 脚本
bytesTxt = check_output(['node','t.js', '3', '6'], timeout=100)
print(bytesTxt.decode('utf8').strip())
if __name__ == '__main__':
test()t.js
function add(x, y) {
return x + y;
}
var args = process.argv.splice(2);
console.log(add(parseInt(args[0]), parseInt(args[1])));【Node.js 指定函数】
#encoding: utf-8
#author: walker
# date: 2019-03-14
# summary: 直接用 Node.js 调用指定 js 函数
from subprocess import check_output
JSCode = r'''
function add(x, y) {
return x + y;
}
function sub(x, y) {
return x - y;
}
function foo(x) {
return x;
}
'''
def test():
jscode = JSCode + 'process.stdout.write(add(3, 2).toString())'
rtn = check_output('node', input=jscode, universal_newlines=True, timeout=100)
print(rtn)
if __name__ == '__main__':
test()【相关阅读】
*** walker ***
上一篇: Python3实现——反弹shell
下一篇: python3 Django 报错Run
51135
50538
41153
37991
32456
29359
28228
23073
23042
21366
1405°
2096°
1747°
1675°
1970°
1753°
2426°
4084°
3960°
2831°