Shell Meteor JS在客户端html上模拟服务器命令行
我是流星新手,想做一个简单的应用。我无法根据以下命令在服务器端模拟命令行 当我在客户端macosxmavericks上输入命令并点击Run按钮时,结果是空的。我使用的是上面网站的代码,除了我有自动运行和exec=Npm.require'child_process'.exec 下面是我的html和js文件 TerminalApp.htmlShell Meteor JS在客户端html上模拟服务器命令行,shell,meteor,Shell,Meteor,我是流星新手,想做一个简单的应用。我无法根据以下命令在服务器端模拟命令行 当我在客户端macosxmavericks上输入命令并点击Run按钮时,结果是空的。我使用的是上面网站的代码,除了我有自动运行和exec=Npm.require'child_process'.exec 下面是我的html和js文件 TerminalApp.html <head> <title>MeteorJS terminal</title> </head> <b
<head>
<title>MeteorJS terminal</title>
</head>
<body>
{{> terminal}}
</body>
<template name="terminal">
<pre>{{ window }}</pre>
<input id="command" type="text" value="{{ last_cmd }}" />
<input type="button" value="Run" />
</template>
我错过了什么?如何调试?提前谢谢 下面是一个工作示例。输出将位于终端。希望有帮助 terminal.html
Replies = new Meteor.Collection('replies');
if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Welcome to terminal.";
};
Template.hello.events({
'click #button': function () {
console.log("clicking");
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();
});
}
});
}
我们不再直接使用光纤npm模块,而是使用Meteor.bindEnvironment,如下所述: 在这里:
<head>
<title>terminal</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<input type="text" id="command">
<input type="button" id="button" value="Click" />
</template>
Replies = new Meteor.Collection('replies');
if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Welcome to terminal.";
};
Template.hello.events({
'click #button': function () {
console.log("clicking");
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();
});
}
});
}