node.js - NodeJS 捕获 NODEJS 命令的输出并显示到表达窗口
问题描述
注意:我不想捕获 bash 命令的输出,而是像这样的命令:
console.log(1)
它只是在我的快速服务器上说 1 而不是将其记录到控制台
我对 NodeJs 非常陌生,但精通 python
这是我的代码:
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send(req.param('cmd')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
如果我这样做,我想要:
prtc://my.server?cmd=console.log(1)
该页面将显示 1。
我该怎么做?
解决方案
我自己用 PHP 做的。
对于任何需要代码的人,请在 REPL.IT 或 HEROKU 或类似网站上运行它。
<?php
$lang = $_GET['lang'];
$command = $_GET['cmd'];
if ($lang == 'sh') {
System($command);
};
if ($lang == 'python3') {
System('python3 -c "'.$command.'"');
};
if ($lang == 'python2') {
System('python2 -c "'.$command.'"');
};
if ($lang == 'node14') {
$fp = fopen('cmds.js', 'w');
fwrite($fp, $command);
System('node cmds.js');
unlink('cmds.js');
};
?>
推荐阅读
- swift - Swift - AES base64 + md5 解密
- codenameone - 如何将多个容器绑定在一起?
- javascript - 如何克隆网页及其 css 元素和脚本?
- node.js - 如何通过不同的api使用socket io连接服务器和客户端?
- javascript - Discord.js Avatar 命令无法提及用户
- apache-spark - 使用聚合函数时出现火花数据框错误
- javascript - 如何使用 Python 从 javascript 网页中抓取 HTML
- java - 在 spring 中注入 config.xml 数据源中调用方法的结果
- mysql - 用数字对 MySQL 文本列进行排序
- javascript - 换行时更改 html 标签