我試圖管道標準輸出&標準輸入的child_process到瀏覽器&顯示它在HTML頁面。我正在使用browserify來讓node.js在瀏覽器上運行。我產生child_process的代碼就像這樣。管道子進程標準輸出和標準輸入瀏覽器在node.js和browserify
var child = require('child_process');
var myREPL = child.spawn('myshell.exe', ['args']);
// myREPL.stdout.pipe(process.stdout, { end: false });
process.stdin.resume();
process.stdin.pipe(myREPL.stdin, { end: false });
myREPL.stdin.on('end', function() {
process.stdout.write('REPL stream ended.');
});
myREPL.on('exit', function (code) {
process.exit(code);
});
myREPL.stdout.on('data', function(data) {
console.log('\n\nSTDOUT: \n');
console.log('**************************');
console.log('' + data);
console.log('==========================');
});
我使用browserify創建了一個bundle.js,我的html看起來像這樣。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="bundle.js"></script>
<script src="main.js"></script>
</head>
<body>
</body>
</html>
我試圖避免運行http服務器,並在瀏覽器中將結果傳遞給它。有什麼其他的方式可以做到嗎? 謝謝
什麼問題?任何錯誤消息? –
是的,所以在瀏覽器process.stdin&process.stdout是未定義的,這是有道理的,因爲瀏覽器不會支持它。但我不知道如何解決它 – ssarangi