0
我試圖從JavaScript執行bash命令並獲取它的輸出。JavaScript中的Bash命令
如何傳遞一個js變量作爲bash函數的參數?
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('checkPage');
checkPageButton.addEventListener('click', function() {
chrome.tabs.getSelected(null, function(tab) {
var tablink = tab.url;
tablink.split("=")
var ytid = tablink[1]
var cp = require('child_process');
var ls = cp.spawn('ytdownload', ['-x --audio-format m4a --audio-quality 0 -o '/Users/GregoireMarie/Music/%(title)s.%(ext)s' https://www.youtube.com/watch?v='], ytid);
ls.stdout.on('data', function(data) {
\t console.log('Message: ' + data);
ls.on('close', function(code, signal) {
\t console.log('ytdownloader is finished...');
});
});
}, false);
}, false);
我不是一個有經驗的developper可言,只是想獲得一個可愛的小腳本工作下載音樂:)
https://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-javascript –