Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawn process #2

Merged
merged 2 commits into from
May 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion new_index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- A sample where you can record your voice and it can be played back -->
<!-- Source: http://codeartists.com/post/36746402258/how-to-record-audio-in-chrome-with-native-html5-apis -->
<!-- Original source: http://codeartists.com/post/36746402258/how-to-record-audio-in-chrome-with-native-html5-apis -->
<!-- Adapted by Alex Popof for CS 224S - May 2014 -->
<html>
<body>
<audio controls autoplay></audio>
Expand Down
31 changes: 31 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ var fs = require('fs');
var url = require('url');
var fs = require('fs');

var exec = require('child_process').exec;
var spawn = require('child_process').spawn;

var server = http.createServer(function(req,rep){
console.log('connection');
var path = url.parse(req.url).pathname;
Expand Down Expand Up @@ -82,6 +85,34 @@ var server = http.createServer(function(req,rep){
rep.end();
});
break;
// sample invocations of command line process (wc)
// http://stackoverflow.com/questions/20643470/execute-a-command-line-binary-in-node-js
// execute_all: fetches complete output
// execute_online: receives output as streams
case '/execute_all':
exec('wc recorder.js',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
if (error !== null) {
console.log('exec error: ' + error);
}
});
rep.writeHead(200, {'Content-Type':'text/html'});
rep.write("<html><body>Executing command ... fetch complete output</body></html>");
rep.end();
break;
case '/execute_online':
// command and its list of args
var child = spawn('wc', ['recorderWorker.js', '-l']);
child.stdout.on('data', function(chunk) {
var returnedText = chunk.toString();
// need to parse buffer data bytes into ascii
console.log(returnedText);
});
rep.writeHead(200, {'Content-Type':'text/html'});
rep.write("<html><body>Executing command ... fetch in chunks</body></html>");
rep.end();
break;
default:
console.log("default path");
rep.writeHead(404);
Expand Down