AntiMicroX / antimicrox

Graphical program used to map keyboard buttons and mouse controls to a gamepad. Useful for playing games with no gamepad support.
GNU General Public License v3.0
2.43k stars 141 forks source link

Shebang ignored in execute bind (all scripts run in sh) #699

Closed vlad2305m closed 1 year ago

vlad2305m commented 1 year ago

Is there an existing issue for this?

Current Behavior

I wrote a script in fish only to discover that it is not working.

#!/usr/bin/fish
echo $(ps -p $$)
...

Output:

PID TTY TIME CMD 39304 ? 00:00:00 sh
...
[error wrong syntax]

#!/bin/bash also runs in sh instead. ps -p $fish_pid => error: list of process IDs must follow -p bash shell runs the file in fish as expected

Expected Behavior

For shebang to be respected and script to run in fish.

Steps To Reproduce

  1. Bind a key to the aforementioned script
  2. Run antimicrox in a terminal
  3. Press the key
  4. Discover that script is being run by sh and that any shell-specific syntax does not work

Environment

Program Version 3.3.2
Program Compiled on Jan 14 2023 at 10:25:43
Built Against SDL 2.26.2
Running With SDL 2.26.2
Using Qt 5.15.8
Using Event Handler: uinput
Compositor type: wayland
Host OS: arch Version: unknown Architecture: x86_64

Anything else?

Workaround: set executable to fish, argument to script (displays as [Exec] fish -> uninformative)

pktiuk commented 1 year ago

currently executable running file depends on fine extension event.cpp

/*
     * shell scripts work, but I am not sure about other extensions
     * neither start method form QProcess nor QProcess::startDetached
     * don't work as expected
     * need to find another way
     */

    if (fileinfo.completeSuffix() == "sh" || firstLine.contains("bin/bash"))
        return "/bin/sh";

In case of launching such a process you should also get able to get some logs:

        if (success)
            qInfo() << "Command: " << slot->getTextData() << " " << argumentsString
                    << " executed successfully with pid: " << pid;
        else
            qWarning() << "Command " << slot->getTextData() << " " << argumentsString << " cannot be executed, pid: " << pid;

In current form code does not care about the shebang.

vlad2305m commented 1 year ago

There is no way this is an enhancement... You can either try reading first line and stripping the shebang and spaces to get path to the executable (an intended way of using shebangs) Or you can add a GUI input field for the location of shell executable (kinda the way I do it now) that then does not display on the button text. Alternatively, you can specify in Readme "/bin/sh scripts" and then supporting other shells will be an enhancement.

vlad2305m commented 1 year ago

Still does not work with /bin/fish

pktiuk commented 1 year ago

In my case, works as expected (tested with your example script).

Terminal test:

pawel@pop-os:/tmp/tmp$ fish ./fish.sh 
./fish.sh (linia 2): $$ nie jest numerem identyfikacyjnym procesu. W fish używane jest $fish_pid.
echo $(ps -p $$)
              ^
warning: Wystąpił błąd podczas odczytywania pliku ./fish.sh

pawel@pop-os:/tmp/tmp$ bash ./fish.sh 
PID TTY TIME CMD 14012 pts/1 00:00:00 bash

AntiMicroX test:

pawel@pop-os:~/antimicrox$ LABNG=en_US ./build/bin/antimicrox 

/tmp/tmp/fish.sh (linia 2): $$ nie jest numerem identyfikacyjnym procesu. W fish używane jest $fish_pid.
echo $(ps -p $$)
              ^
warning: Wystąpił błąd podczas odczytywania pliku /tmp/tmp/fish.sh