Executing a bash script with args within js

PhantomBot Version: 3.0.0
OS Version: Ubuntu 18.04.3 LTS
Java Version: 1.8.0_222
Browser and Version (for Panel Support): Firefox 70.0
Stock PhantomBot: Yes/No (Yes if you have not modified the scripts or Java Core) Yes

Let us know what help you need:
I have a medical need for one of my mods to shut down my stream in case of an emergency. I have a stream kill switch that can be executed from the command line using OBSCommand. Tested and works standalone in a bash script remotely.

I cannot get the javascript to execute my bash script and I have tried several different ways of doing this. I’ve also tried an inputStream but honestly don’t know what that does.

Here is the script, you’ll see I’ve commented out lines that I’ve tried and didn’t work. The runCommand didn’t work unless I defined it.:

(function() {

/*
 * @event command
 */
$.bind('command', function(event) {
    var sender = event.getSender(),
        command = event.getCommand(),
        args = event.getArgs(),
        action = args[0],
        runCommand;
        
    /*
     * @commandpath obs [option] - End Twitch stream
     */
    if (command.equalsIgnoreCase('obs')) {
        if (action !== undefined) {
           /*runCommand("green.sh");*/ 
           java.lang.Runtime.getRuntime().exec('bash ~/phantombot/scripts/commands/green.sh');
           $.say($.whisperPrefix(sender) + $.say('I completed the task'));
        } else {
            $.say($.whisperPrefix(sender) + $.lang.get('obs.usage'));

        }

    }
});

/*
 * @event initReady
 */
$.bind('initReady', function() {
    $.registerChatCommand('./commands/obsCommand.js', 'obs', 1);
});

})();

I’ve tried the runCommand which I just get an: [ERROR] [init.js:317] Error with Event Handler [command] Script [./commands/obsCommand.js] Stacktrace [obsCommand.js:43 > init.js:315 > init.js:510] Exception [TypeError: [email protected] is not a function, it is undefined.]

And when I try the java.lang.Runtime.getRuntime().exec, I don’t get any error and nothing is logged in the /logs/error. The chat log when I use the Runtime.getRuntime().exec is this:
[11-05-2019 @ 10:47:10.681 GMT] devtmi: !obs
[11-05-2019 @ 10:47:21.671 GMT] devtmibot: I completed the task
[11-05-2019 @ 10:47:21.672 GMT] devtmibot: @devtmi, undefined

All I’m trying to do is get the javascript to run my bash script and potentially pass arguments to the bash script in the future. But right now I’m just trying to get the javascript to run my bash script so that it can shut off my stream or turn on my stream.

Try this

new java.lang.ProcessBuilder('/bin/bash', '~/phantombot/scripts/commands/green.sh').start();

Also check your chmod and chown

You may additionally want to replace the tilde with the full path to your home folder

Made the modification, gave absolute path, still nothing. I also checked the running process, if it was successful I should be able to see the process pop up and disappear. But I didn’t see the process execute. Also double checked chmod and chown, read and execute for user and group, write for user. I am missing something just haven’t figured out what.

Double check your PhantomBot logs for an Exception. Especially check logs/stacktrace.txt and logs/error

Yeah that’s the strange thing about it, I cleared out the logs so I know it was fresh. Restarted the bot and ran the command in Twitch. I get the logs for chat and event but in core, error, and stacktraces. I get nothing. No exceptions, errors, or undefined. Is there a way for me to log the output of the line:

new java.lang.ProcessBuilder("/bin/bash", “/home/devtmibot/phantombot/scripts/commands/obs.sh”);

So I can see what is occurring with that line?

Correction, I had double quotes and changed to single quotes. Now I get this in core-error and stacktraces:

[11-06-2019 @ 06:28:47.586 GMT] java.awt.AWTError: Assistive Technology not found: org.GNOME.Accessibility.AtkWrapper
at java.awt.Toolkit.loadAssistiveTechnologies(Toolkit.java:807)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:886)
at java.awt.Toolkit.getEventQueue(Toolkit.java:1736)
at java.awt.EventQueue.invokeLater(EventQueue.java:1294)
at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1295)
at javax.swing.Timer$1.run(Timer.java:614)
at javax.swing.Timer$1.run(Timer.java:612)
at java.security.AccessController.doPrivileged(Native Method)
at javax.swing.Timer.post(Timer.java:612)
at javax.swing.TimerQueue.run(TimerQueue.java:186)
at java.lang.Thread.run(Thread.java:748)

The interesting part is that line is already uncommented out in:

/etc/java-8-openjdk/accessibility.properties