让我们从this question获取此示例应用程序,它允许您运行终端并在输出执行到集合后插入输出。我想知道解决方案可能是什么,在客户端返回带有结果的变量而不使用集合?
<head>
<title>terminal</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<input type="text" id="command">
<input type="button" id="button" value="Click" />
</template>
&#13;
Replies = new Meteor.Collection('replies');
if (Meteor.isClient) {
Template.hello.events({
'click #button': function () {
var cmd = $("input#command").val();
console.log("command", cmd);
var replyId = Meteor.call('command', cmd);
Session.set('replyId', replyId);
}
});
}
if (Meteor.isServer) {
exec = Npm.require('child_process').exec;
Meteor.methods({
'command' : function(line) {
console.log("In command method", line);
Fiber = Npm.require('fibers');
exec(line, function(error, stdout, stderr) {
console.log('Command Method', error, stdout, stderr);
Fiber(function() {
Replies.remove({});
var replyId = Replies.insert({message: stdout ? stdout : stderr});
return replyId;
}).run();
});
}
});
}
&#13;