MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    exec error: Error: Command failed: ?!

    Scheduled Pinned Locked Moved Troubleshooting
    15 Posts 2 Posters 2.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      stoffel
      last edited by

      hallo @ all ,

      i am new here and german, so sorry for my english :-)

      i build my first module. i started with this simple module.

      it works. then i add an exec command

      exec("bash ../MagicMirror/config/test.sh", (error, stdout, stderr) => {
      	if (error) {
      		console.error(`exec error: ${error}`)
      		return;
      	}
      

      thats works ?! i am not sure.
      the test.sh

      cp ../MagicMirror/config/config.js ../MagicMirror/config/config_1.js
      pm2 restart all
      

      in my custom_menu.json i have an entry that send the notification TEST, my MMM_MeinModul.js recieved this and send

      this.sendSocketNotification('START_TEST', {});
      

      when my node_helper.js recieved this then call the function with the exec command.

      the result is an error at pm2 log:

      exec error: Error: Command failed: bash ../MagicMirror/config/test.sh
      

      but thats not true. the pm2 restart all are executed and restart the mm.

      playerRadio
      0|MagicMirror  | [06.07.2021 19:22.56.851] [LOG]   Stopping module helper: MMM-Tools
      0|MagicMirror  | [06.07.2021 19:22.56.883] [ERROR] 
      0|MagicMirror  | exec error: Error: Command failed: bash ../MagicMirror/config/test.sh
      0|MagicMirror  | > magicmirror@2.16.0 start /home/pi/MagicMirror
      0|MagicMirror  | > DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js
      0|MagicMirror  | [06.07.2021 19:23.02.329] [LOG]   
      0|MagicMirror  | Starting MagicMirror: v2.16.0
      
      

      so, i think the cp command not work, but i dont understand the problem.

      here my module

      Module.register("MMM-MeinModul",{
      	defaults: {
      		text: "Sergio"
      	},
      
      	getDom: function() {
      		var wrapper = document.createElement("div");
      		wrapper.innerHTML = this.config.text;
      		return wrapper;
      	},
      
      	start: function() {
      		this.sendSocketNotification('CONFIG', this.config);
      	},
      
      	socketNotificationReceived: function(notification, payload) {
      		if (notification === 'STARTED') {
      			console.log("MMM-MeinModule notification [" + notification + "] payload [" + payload + "]")
      			this.config.text = 'Started';
      			this.updateDom();
      		}
      	},
      	
      	notificationReceived: function(notification, payload) {
      		if (notification === 'TEST') {
      			console.log("MMM-MeinModule notification [" + notification + "] payload [" + payload + "]")
      			this.config.text = 'changed';
      			this.updateDom();
      			this.sendSocketNotification('START_TEST', {});
      		}
      	}
      });
      

      and here my node_helper

      var NodeHelper = require("node_helper");
      const exec = require("child_process").exec;
      
      module.exports = NodeHelper.create({
      	start: function () {
      		this.config = {}
      	},
      	
      copyfile: function () {
      console.log(__dirname)
      exec("bash ../MagicMirror/config/test.sh", (error, stdout, stderr) => {
      	if (error) {
      		console.error(`exec error: ${error}`)
      		return;
      	}
      });
      },
      
      	socketNotificationReceived: function (notification, payload) {
      		if (notification === 'CONFIG') {
      			this.config = payload;
      			console.log("MMM-MeinModule node_helper (config) notification [" + notification + "] payload [" + payload + "]")
      			this.sendSocketNotification('STARTED',payload);
      		}
      		if (notification === 'START_TEST') {
      			console.log("MMM-MeinModule node_helper (TEST) notification [" + notification + "] payload [" + payload + "]")
      			this.copyfile();
      		}
      	}
      });
      

      can sameone get a hint please ?

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @stoffel
        last edited by

        @stoffel make sure to change to the right folder …

        console.log(__dirname) is where the source file is located, NOT the current folder

        when modules are executed, the current folder is where the caller is…

        pm2 doesn’t launch MM from within the MM folder…

        best to use the full path

        this.path is the full path to the module folder

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          stoffel @sdetweil
          last edited by

          hallo sdetweil,

          have you finished your config-module :face_with_steam_from_nose: ?

          the __dirname was from the beginning when i have a file not found error. now its found and i think the exec comand works, in log you can see after the error restart mm but i have no error message from then cp command. so i can not find whats the problem is. in the console.log i have no errors. where can i see error messages from the cp command.

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @stoffel
            last edited by

            @stoffel yes, my config module is pretty good…
            waiting for more error reports from users …

            because you are launching the program (bash) … the console comes to your program not to the log…

            in my uploadPics module I just console.log() whatever comes back from my shell pgm…
            then it shows in the MM log

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            S 2 Replies Last reply Reply Quote 0
            • S Offline
              stoffel @sdetweil
              last edited by

              @sdetweil

              fine, i will test it at WE.
              Now its time to sleep. i test tomorrow with sh … and without bash/sh

              1 Reply Last reply Reply Quote 0
              • S Offline
                stoffel @sdetweil
                last edited by

                @sdetweil

                i’v test the exec command without bash… thats not work, i have a
                /bin/sh: 1: …/MagicMirror/config/test.sh: Permission denied

                with bash it works now, but the filename is a bit crazy
                cp config.png

                thats at ssh console. in filezilla the filename is correct but says no such file or directory

                i have no idea what gos wrong

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  sdetweil @stoffel
                  last edited by sdetweil

                  @stoffel us the file marked excecutable?

                  ls -laF ../MagicMirror/config/test.sh

                  if the file starts with the shebang, then u don’t need to use bash either

                  #!/bin/bash
                  rest of script
                  

                  chmod +x ../MagicMirror/config/test.sh

                  it is really in the config folder?

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  S 1 Reply Last reply Reply Quote 0
                  • S Offline
                    stoffel @sdetweil
                    last edited by

                    @sdetweil

                    look at my first post, its a simple text-file with the extension .sh and its executable -rw-r–r–
                    the test.sh is not the problem, the file ist found and execute it. the problem was the cp command. but now i soved the problem.

                    cp -a -v ../MagicMirror/config/config.js ../MagicMirror/config/config_1.js 1>> ./log_erfolgreich.txt 2>> ./log_fehlgeschlagen.txt
                    pm2 restart all
                    

                    i add the option -a . now its work !!
                    the log_erfolgreich.txt and log_fehlgeschlagen.txt are found in the MagicMirror dir, so cp starts at this dir.
                    the

                    ../MagicMirror/
                    

                    are needed, maybe mm starts from the .pm2 dir?!

                    i play around with it and other files (txt, png…)
                    i am lucky :-)
                    thanks very much for your help.

                    at WE i test your config-module and post it

                    S 2 Replies Last reply Reply Quote 0
                    • S Offline
                      sdetweil @stoffel
                      last edited by

                      @stoffel said in exec error: Error: Command failed: ?!:

                      and its executable -rw-r–r–

                      is NOT executable

                      it needs the x flag

                      now its executable xrwxr–xr–

                      there are 3 bits each

                      for the user themselves
                      for others in the same group as the user
                      and for ‘others’

                      sometimes shortened to UGA

                      u can set the flags with
                      chmod the numbers 7 is all bits (777)
                      or just for the user 766
                      or read only for anyone except the user 744

                      to turn on the execute flag for any and all its +x
                      (to turn it off is -x)
                      r and w are read and write

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        sdetweil @stoffel
                        last edited by

                        @stoffel said in exec error: Error: Command failed: ?!:

                        its a simple text-file

                        unix is cool… ANYTHING can be executable… and a ‘script’ is just a text file with the executable flag on
                        the .sh means nothing (just convention to say shell script)

                        I dson’t use .sh in most of my scripts, cause its just another thing the user has to type and doesn’t help

                        also, in unix, if the 1st line of the executable text file

                        starts with shebang #!
                        then the program to execute this ‘script’ is specified next

                        #!/bin/bash 
                        

                        means bash will execute this program, so bash (/bin/bash) is launched and passed this script

                        Sam

                        How to add modules

                        learning how to use browser developers window for css changes

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Sam, technical setup by Karsten.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy