我想通过单击 html 按钮连接到“server.js”文件。
“server.js”文件正在使用 shell.js 运行“bash.sh”文件
任何人都可以就如何进行提供一些想法或指导吗?
按钮.html
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script src="server.js"></script>
</body>
客户端.js
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
服务器.js
const shell = require('shelljs');
shell.exec('./bash.sh')
bash.sh
#!/bin/bash
printf "command 1 is running...\n\n"
mlpack_linear_regression --training_file aircon.csv -v -M lr.xml
printf "\ncommand 2 is running...\n\n"
mlpack_linear_regression --training_file aircon.csv --test_file
predict.csv --output_predictions_file prediction.csv -v
printf "\nPredicted Output: \n\n"
cat prediction.csv # after this command the result should shown on
#the browser screen
echo "hello" >> file # To test if connection is happening or not
#by writing a string in a file