calling child_process from nodejs
calling child_process from nodejs
我有一个html文件,其中包含一个调用javascript函数的超链接。javascript函数必须调用一个批处理文件。。。这一切都应该在Node.js 中发生
<html>
<head>
<title>sample</title>
<script src="child.js"></script>
</head>
<body>
<a href="#" onclick="call()">click here</a>
</body>
</html>
child.js
function call()
{
var spawn = require('child_process').spawn,
ls = spawn('append.bat');
}
我犯了这样的错误。。。。
ReferenceError: require is not defined
var spawn = require('child_process').spawn,
任何答案。。请回复。。。
http.Server
并使用Ajax在其间进行通信。
一个部分示例(使用一些库来简化)是:
// server-side
app.post('/append', function (req, res) {
exec('appand.bat', function (err, stdout, stderr) {
if (err || stderr.length) {
res.send(500, arguments);
} else {
res.send(stdout);
}
});
});
// client-side
function call() {
$.post('/append').done(function (ls) {
console.log(ls);
}).fail(function (xhr) {
console.error(xhr.responseText);
});
}
演示的库是Express用于服务器端,jQuery用于客户端。它还使用child_process.exec()
而不是spawn()
来获得Buffer
s而不是Stream
s。
资源:
- 学习jQuery
- 快速指南
- SO的
node.js
标签信息,其中包括许多"教程、指南和书籍"answers"Free Node.js书籍和资源。"
您无法从浏览器访问Node.js。
相关文章:
- nodejs-expressjs上传图像并显示它们
- TypeError:在不兼容的接收器nodejs上调用了方法Uint8Array.length
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- NodeJS日期格式不起作用
- Nested Q.all nodejs
- Nodejs API控制器,用于在API之间切换
- 否'访问控制允许来源'标头存在于IISNOde中请求的资源(AngularJS+NodeJs)上
- 如何在大型nodeJS代码的基础上逐步引入typescript
- 在Nodejs中Express输入DEBUG=app时权限被拒绝/bin
- 无法使用nodeJS在html中设置Image src
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- NodeJS API调用中Array中的Push和Pull元素
- 基于api密钥的NodeJS web服务
- 在gump和nodejs中使用Typescript时,未定义对require和exports的引用
- NodeJS - Downloading from Google Drive
- Run InDesign ExtendedScript from nodejs
- AngularJS taking JSON from nodejs API
- Controlling Arduino From NodeJS
- calling child_process from nodejs
- Calling PowerShell from NodeJS