我的腳本的這一部分正在嘗試產生一個將克隆硬盤驅動器的孩子。它基本上可行,但我遇到的問題是當我遇到錯誤並想要存儲輸出時,它只存儲輸出的第一行,排除我實際需要的東西。我在腳本之外運行命令,它給了我兩行輸出,第二行是失敗的錯誤。所以,我怎麼能存儲整個輸出。非常感謝幫助,謝謝!節點產卵過程和存儲輸出
NtfsPartition.prototype.WriteFs = function(filename, progress, success, error) {
console.log('Writing NTFS FS');
var s = spawn("ntfsclone", ['--restore-image', '--overwrite', this.dev, filename]);
var err_msg = '';
s.on('error', function(err) {
err_msg = err;
});
s.stderr.on('data', function(data) {
err_msg += data.toString();
});
s.stdout.on('data', function(data) {
var match = data.toString().match(kNtfsWriteFsProgressRegex);
if(!match) {
return;
}
progress(match[1]);
});
s.on('exit', function(code) {
if(code != 0) {
console.log(err_msg);
return error('Error: ' + code + ' - ' + err_msg);
}
success();
});
}
歡迎來到Stack Overflow!這是一個很好的第一個問題,我們期待着您對社區的進一步貢獻。我只是添加了一些標籤以使您的問題更容易找到,並且爲了將來參考,您可以使用4個空格縮進大塊代碼,而不是使用內聯反引號。雖然這些都是非常小的細節,並且我確信快速訪問[幫助]會教你一些其他好的提示。 –