0

I'm trying to execute a bash command from JavaScript and get the output of it.

How to pass a js variable as a parameter of a bash function?

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) {
   console.log('Message: ' + data);

ls.on('close', function(code, signal) {
 console.log('ytdownloader is finished...');
    
});
    });
  }, false);
}, false);

I'm not an experienced developper at all, just trying to get a lil script working to download music :)

Anosen
  • 1

1 Answers1

2

You will not be able to execute a bash script on the client machine. Your code is running in a browser, and you are trying to use the Node.js API. This API can only be used on the server side.

Olivier Liechti
  • 3,138
  • 2
  • 19
  • 26
  • https://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-javascript – xGeo Sep 30 '17 at 17:38