Same command works from terminal but doesn't when automated #821

Open
opened 2023-10-30 17:47:16 +01:00 by DeutscheGabanna · 4 comments
DeutscheGabanna commented 2023-10-30 17:47:16 +01:00 (Migrated from github.com)

Let's say I open up another terminal, for example - kgx - or even cool-retro-term. I want a new instance of cool-retro-term with a specific command, so I type in:

cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags <some_files_comma_separated>'

For example:

cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags "/home/deutschegabanna/local/documents/biel-incongruity-of-company-law-terms-mix -- article legal.html" "/home/deutschegabanna/local/documents/english-for-tax-professionals-reference-book-en -- finance legal book.txt" "/home/deutschegabanna/local/documents/semi-automatic-wild-cards-for-polish-inflections.txt"'

It works. Another window pops up with the correct output for tagging files:

Please enter tags, separated by " "; abort with Ctrl-C; complete 10 tags with TAB
                     
         .--------, 
        | o   ?   | 
         `--------' 
                     

  Top nine previously used tags in this directory:
    article (1) ⋅ book (2) ⋅ dictionary (3) ⋅ finance (4) ⋅ languages (5) ⋅ legal (6) ⋅ personal (7) ⋅ politics (8) ⋅ tech (9)

Tags: 

But now let's do exactly the same, but from Nautilus automated script. (I know what you want to reply - "It's a Nautilus issue" - please, let me explain in full).

My .sh script basically amounts to running the same command as above. Identical:

cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags "/home/deutschegabanna/local/documents/biel-incongruity-of-company-law-terms-mix -- article legal.html" "/home/deutschegabanna/local/documents/english-for-tax-professionals-reference-book-en -- finance legal book.txt" "/home/deutschegabanna/local/documents/semi-automatic-wild-cards-for-polish-inflections.txt"'

How do I know this? By outputting the wanna-be-result into a file. The script:

#!/bin/bash

# Declare an array to store file paths
file_paths=()

# Split the selected file paths into an array
IFS=$'\n' read -d '' -ra file_paths <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"

# Iterate through the array and format the paths
for file in "${file_paths[@]}"; do
    # Enclose each file path in quotation marks and append it to the array
    formatted_file="\"$file\""
    formatted_paths+=("$formatted_file")
done

# Join the array into a single string with space-separated items
formatted_paths="${formatted_paths[*]}"

# Open new instance of the terminal and run filetags <filepaths>
# THIS IS THE DEBUG LINE TO COMPARE FINAL COMMANDS
echo "cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags $formatted_paths'" > try.txt
cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags $formatted_paths'

And the moment of truth, let's compare try.txt to my manual command:

cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags "/home/deutschegabanna/local/documents/biel-incongruity-of-company-law-terms-mix -- article legal.html" "/home/deutschegabanna/local/documents/english-for-tax-professionals-reference-book-en -- finance legal book.txt" "/home/deutschegabanna/local/documents/semi-automatic-wild-cards-for-polish-inflections.txt"'

They are the same!
And yet, if I launch my Nautilus script, the cool-retro-term opens... starts complaining about missing pip packages (as if the .bashrc environmental vars weren't properly loaded) and exits within milliseconds.

How do I fix this? I debugged this to my limit, trying for three days now.

Let's say I open up another terminal, for example - `kgx` - or even cool-retro-term. I want a new instance of cool-retro-term with a specific command, so I type in: ``` cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags <some_files_comma_separated>' ``` For example: ``` cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags "/home/deutschegabanna/local/documents/biel-incongruity-of-company-law-terms-mix -- article legal.html" "/home/deutschegabanna/local/documents/english-for-tax-professionals-reference-book-en -- finance legal book.txt" "/home/deutschegabanna/local/documents/semi-automatic-wild-cards-for-polish-inflections.txt"' ``` It **works**. Another window pops up with the correct output for tagging files: ``` Please enter tags, separated by " "; abort with Ctrl-C; complete 10 tags with TAB .--------, | o ? | `--------' Top nine previously used tags in this directory: article (1) ⋅ book (2) ⋅ dictionary (3) ⋅ finance (4) ⋅ languages (5) ⋅ legal (6) ⋅ personal (7) ⋅ politics (8) ⋅ tech (9) Tags: ``` But now let's do **exactly** the same, but from Nautilus automated script. _(I know what you want to reply - "It's a Nautilus issue" - please, let me explain in full)._ My .sh script basically amounts to running the same command as above. **Identical**: ``` cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags "/home/deutschegabanna/local/documents/biel-incongruity-of-company-law-terms-mix -- article legal.html" "/home/deutschegabanna/local/documents/english-for-tax-professionals-reference-book-en -- finance legal book.txt" "/home/deutschegabanna/local/documents/semi-automatic-wild-cards-for-polish-inflections.txt"' ``` How do I know this? By outputting the wanna-be-result into a file. The script: ``` #!/bin/bash # Declare an array to store file paths file_paths=() # Split the selected file paths into an array IFS=$'\n' read -d '' -ra file_paths <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" # Iterate through the array and format the paths for file in "${file_paths[@]}"; do # Enclose each file path in quotation marks and append it to the array formatted_file="\"$file\"" formatted_paths+=("$formatted_file") done # Join the array into a single string with space-separated items formatted_paths="${formatted_paths[*]}" # Open new instance of the terminal and run filetags <filepaths> # THIS IS THE DEBUG LINE TO COMPARE FINAL COMMANDS echo "cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags $formatted_paths'" > try.txt cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags $formatted_paths' ``` And the moment of truth, let's compare `try.txt` to my manual command: ``` cool-retro-term -e /bin/bash -c 'source ~/.bashrc; filetags "/home/deutschegabanna/local/documents/biel-incongruity-of-company-law-terms-mix -- article legal.html" "/home/deutschegabanna/local/documents/english-for-tax-professionals-reference-book-en -- finance legal book.txt" "/home/deutschegabanna/local/documents/semi-automatic-wild-cards-for-polish-inflections.txt"' ``` They are **the same**! And yet, if I launch my Nautilus script, the cool-retro-term opens... starts complaining about missing pip packages (as if the .bashrc environmental vars weren't properly loaded) and exits within milliseconds. How do I fix this? I debugged this to my limit, trying for three days now.
Sectonidse commented 2024-01-04 13:29:06 +01:00 (Migrated from github.com)

I have the same issue and want it fixed... I tried to execute cool-retro-term from standard terminal - works, from scripts (such as bash, Python scripts and even Cinnamon launchers and launching command through KDE Connect) - doesn't work.

I have the same issue and want it fixed... I tried to execute cool-retro-term from standard terminal - works, from scripts (such as bash, Python scripts and even Cinnamon launchers and launching command through KDE Connect) - doesn't work.
Sectonidse commented 2024-01-04 13:37:54 +01:00 (Migrated from github.com)

The interesting thing is, when trying to execute cool-retro-term with --verbose, it doesn't tell that there's errors, it only tells that qml is loading, then storing the settings.

The interesting thing is, when trying to execute cool-retro-term with --verbose, it doesn't tell that there's errors, it only tells that qml is loading, then storing the settings.
Sectonidse commented 2024-01-04 14:43:07 +01:00 (Migrated from github.com)

What i found out is that it keeps running if you append & sleep 5 into the command, but the window instantly closes when launched... I consider this a bug now.

What i found out is that it keeps running if you append `& sleep 5` into the command, but the window instantly closes when launched... I consider this a bug now.
DeutscheGabanna commented 2024-06-05 12:33:53 +02:00 (Migrated from github.com)

Yeah, I tried to get some attention in a similar thread here: https://github.com/Swordfish90/cool-retro-term/issues/728#issuecomment-2149456156 but to no avail @Sectonidse

Yeah, I tried to get some attention in a similar thread here: https://github.com/Swordfish90/cool-retro-term/issues/728#issuecomment-2149456156 but to no avail @Sectonidse
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: seeseemelk/cool-retro-term#821
No description provided.