Created
April 19, 2012 06:48
-
-
Save dongyuwei/2419203 to your computer and use it in GitHub Desktop.
nodejs spawn svn cmd ,chunked putput to broswer ; 在浏览器上实时查看svn命令输出
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), spawn = require('child_process').spawn; | |
var util = require('util'); | |
var app = express.createServer(); | |
app.use(app.router); | |
var svn; | |
app.get('/svn', function(req, res) { | |
res.writeHead(200, { | |
'Content-Type': 'text/html;charset=utf-8' | |
}); | |
res.write('<script>window._timer_ = setInterval(function(){try{document.body.scrollTop = document.body.offsetHeight;}catch(e){}},5);</script>','utf-8'); | |
svn = spawn('svn', ['export','--non-interactive','--trust-server-cert','--force', '--username','yuwei', '--password','myPassword', 'https://svn1.intra.sina.com.cn/weibo/ria/t4/home/dev/trunk']); | |
svn.stdout.on('data', function(data) { | |
data.toString().split('\n').forEach(function(line){ | |
line && res.write('<li>' + line + '</li>','utf-8'); | |
}); | |
}); | |
svn.stderr.on('data', function(data) { | |
console.log('stderr: ' + data); | |
res.write(data, 'utf-8'); | |
}); | |
svn.on('exit', function(code) { | |
console.log('svn process exited with code ' + code); | |
res.end('<script>clearInterval(window._timer_);</script>','utf-8'); | |
}); | |
}); | |
app.get('/test', function(req, res) { | |
res.header('Content-Type' ,'text/html'); | |
res.end('test','utf-8'); | |
}); | |
app.listen(8080); | |
console.log('server ' + process.pid + ' running on 8080 port...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
加上
'Transfer-Encoding':'chunked'
效果会不会更加好