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 :)

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.