Bug 436950 - Konsole --tabs-from-file command behavior is opaque and hard to debug
Summary: Konsole --tabs-from-file command behavior is opaque and hard to debug
Status: CONFIRMED
Alias: None
Product: konsole
Classification: Applications
Component: general (show other bugs)
Version: 21.12.3
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-12 02:20 UTC by skierpage
Modified: 2024-06-13 19:38 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description skierpage 2021-05-12 02:20:02 UTC
SUMMARY
I've been fighting konsole --tabs-from-file for an hour just trying to make it run some commands in a tab that sticks around.

STEPS TO REPRODUCE
1. Add the following to ~/konsole_tabs file:
title: Echo %d : %n;; command: echo 123456
title: Echo background;; command: echo Did anything happen &
title: Cat;; command: cat -
title: Bad;; command: badprogramname

2. Run `konsole --tabs-from-file ~/konsole_tabs

3. Run `konsole --hold --tabs-from-file ~/konsole_tabs


OBSERVED RESULT
The echo command completes; but without --hold the tab goes away.
The echo background tab goes away; with --hold you get a red error message
> Warning: Could not find 'echo Did anything happen &',...

The cat command echoes input, but when you press Ctrl-D, the tab goes away.
The bad tab helpfully tells you in red
>  Warning: Could not find 'badprogramname', starting (your shell)...

In the terminal where you ran this, konsole displays
>  [18::30:59.234] unknown: "Could not find binary: " ""
>  [18::30:59.301] unknown: "Could not find binary: " "badprogramname"

EXPECTED RESULT
This need not be so prone to error and confusion.

(A) The number one thing that would help is to change https://docs.kde.org/stable5/en/konsole/konsole/command-line-options.html to say "Use the --hold command-line option with --tabs-from-file, it can help debug any problems."

(B) The next thing is for the documentation to explain how the heck
> command: a command to run

actually works. Is "command" interpreted by a shell? (No, I think). Can it have arguments (yes, I think). Are any environment variables available? (I don't know). Can you have more than one command? (I don't think so.) Is it possible to have more than one command? (I Googled for hours and tried dozens of command lines). Can you have the shell stick around, remaining interactive? (I don't think so, though surely this is a common desire!)

(C) The console output should be much more helpful. Instead of:
> [18::36:1.771] unknown: "Could not find binary: " ""
It should say something more useful, like
  konsole --tabs-from-file option had problem with tab titled "Echo sleep" executing command `echo Did anything happen &`, error is 'Could not find binary " "'.

(D) It should be easier to have the tab run one or more commands and then become a normal interactive shell, either by modifying Konsole's behavior or documenting how to do this. The behavior when you ask Konsole to run `badprogramname` and it tells you it had a problem then runs your shell seems generally useful; in the case of success it could print a similar message in green then run your shell.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
KDE Plasma Version:5.21.5
KDE Frameworks Version: 5.81.0
Qt Version: 5.15.2 Wayland

ADDITIONAL INFORMATION
Examples of the hair-pulling this causes:
* https://forum.kde.org/viewtopic.php?f=227&t=152305
* https://forum.kde.org/viewtopic.php?f=227&t=160124
* https://stackoverflow.com/questions/32779281/how-to-launch-a-kde-konsole-with-multiple-tabs-running-various-progs

Konsole is demonstrably difficult to automate, but thanks for a great terminal program!
Comment 1 Thomas Dreibholz 2023-12-12 10:01:34 UTC
I can confirm the unexpected and undocumented behaviour of Konsole (using konsole 21.12.3, under Kubuntu 22.04):

Test tabs file contents:
-----
title: test1;; command: date;;
title: test2;; command: /bin/bash -c 'date && sleep 60';;
title: test3;; command: /bin/bash -c "date && sleep 60";;
title: test4;; command: /bin/bash -c \'date && sleep 60\';;
title: test5;; command: /bin/bash -c \"date && sleep 60\";;
title: test6;; command: /bin/bash -c \'date \&\& sleep 60\';;
title: test7;; command: /bin/bash -c \"date \&\& sleep 60\";;
title: test8;; command: date;;
-----

It seems Konsole is not properly handling quotations (tried: " and '), which makes it impossible to write a more complex command call as call to a shell with the actual command line as parameter. test2 and test3 fail with:
&&: -c: line 1: unexpected EOF while looking for matching `''
&&: -c: line 2: syntax error: unexpected end of file
This may be a bug in the command parsing code? At least, the documentation (https://docs.kde.org/stable5/en/konsole/konsole/command-line-options.html) should clearly specify how to handle quotations.

The "--hold" option is really useful for debugging --tabs-from-file issues. This should be clearly stated by the documentation!

Trying to escape the quotation marks is not successful as well (test4 to test7).
Comment 2 Thomas Dreibholz 2023-12-12 10:19:15 UTC
Further unexpected behaviour:
-----
title: test12;; command: pwd;;
title: test13;; command: ./access 172.19.255.101;;
title: test14;; command: <ABSOLUTE-PATH-TO-THE-SCRIPTS-DIRECTORY>/access 172.19.255.101;;
-----

test12 provides the current directory. In may test case, it contains a script "access".

test13 fails:
Warning: Could not find './access 172.19.255.101', starting '/bin/bash' instead.  Please check your profile settings.

/bin/bash: 172.19.255.101: No such file or directory

Konsole seems to misinterpret './access 172.19.255.101' as the command name, i.e. not split between command and arguments.

test14: This one works!

Konsole seems to make a difference between absolute paths (test14) and relative paths (test13).
Comment 3 TraceyC 2024-06-13 19:38:00 UTC
Related: https://bugs.kde.org/show_bug.cgi?id=488396