Bug 366793 - Regression in Konsole's handling of command line parameters
Summary: Regression in Konsole's handling of command line parameters
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: general (show other bugs)
Version: master
Platform: openSUSE Linux
: NOR major
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords: regression
: 367588 368899 369040 369297 369314 374625 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-08-15 16:29 UTC by Wolfgang Bauer
Modified: 2017-12-20 15:08 UTC (History)
25 users (show)

See Also:
Latest Commit:
Version Fixed In: 17.04.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Bauer 2016-08-15 16:29:31 UTC
Starting with 16.08.0, starting Konsole with a command line like this doesn't work any more:
konsole -e sh -c "echo test"

Reproducible: Always

Steps to Reproduce:
1. Run konsole -e sh -c "echo test"


Actual Results:  
konsole: Unknown option 'c'.
konsole: Use --help to get a list of available command line options.
Speicherzugriffsfehler

(as you can see it also crashes with a segmentation fault, but that's not the topic of this bug report...)

Expected Results:  
A konsole window should pop up, displaying the text "test".
(of course it would close immediately again, adding the "--keep" parameter should fix that)

The same works fine with konsole 16.04.3.
Therefore it's probably related to the switch to Qt's QCommandLineParser, i.e. porting away from kdelibs4support (so maybe a bug/limitation in Qt?).

I stumbled over this when investigating why installing debug symbols in drkonqi doesn't work any more in openSUSE with the latest git packages.
drkonqi's installdbgsymbols.sh script uses a similar construct to actually install the packages.
Comment 1 Wolfgang Bauer 2016-08-15 16:40:49 UTC
I'd like to add that konsole 16.08.0's command line help still says this:
$ konsole --help
Usage: konsole [options] [args]
Terminal emulator

Options:
...
  -e <cmd>                   Command to execute. This option will catch all
                             following arguments, so use it as the last option.
...

So according to the documentation, this is supposed to work... ;-)
Comment 2 Raymond Wooninck 2016-08-16 19:44:51 UTC
It seems as parsing the command line is the issue and that everything is seen as an option to konsole.  Using konsole -e "sh -C "echo test"", then it works fine.
Comment 3 Wolfgang Bauer 2016-08-16 20:28:21 UTC
(In reply to Raymond Wooninck from comment #2)
> It seems as parsing the command line is the issue and that everything is
> seen as an option to konsole.

Yes, obviously.
But -e should "capture" all following options, and it does in previous konsole versions (which used kdelibs4support, i.e. KCmdLineArgs, for parsing the command line).

>  Using konsole -e "sh -C "echo test"", then it
> works fine.

No, it doesn't.
This displays the following error message in the new konsole window:
/usr/bin/test: /usr/bin/test: cannot execute binary file

konsole -e "sh -c \"echo test\"" would work though.

Btw:
(In reply to Wolfgang Bauer from comment #0)
> (of course it would close immediately again, adding the "--keep" parameter
> should fix that)
I wanted to write "--hold" of course, not "keep".
Comment 4 Wolfgang Bauer 2016-08-17 11:21:43 UTC
Btw, this works as expected:
konsole -e echo test
(or konsole --hold -e echo test)
or even:
konsole -e echo This is a test

Both print the given text in the new konsole window.

So the problem only seem to occur if there is another option (with '-') following the -e.
Comment 5 Christian González 2016-08-19 16:00:15 UTC
It seems that this bug is also affecting URLs with the "ssh://user@server" schema.

For example: I use KeePassX2 to store all users, passwords and URLs (http//, ssh//, etc.) for all my servers. When I click on a URL, it launches "xdg-open ssh://user@server" and in turn xdg-open launches "ktelnetservice5 ssh://user@server". Before 16.08.0, Konsole was launched with a SSH session established. Now, ktelnetservice5 just end without results. (In one of my test it shows the message "Unknown option 'l'" but I can't reproduce it anymore. I guess the 'l' option means the 'l' parameter from ssh client so maybe ktelnetservice5 is using the "ssh -l user server" sintax and it raises this bug.)
Comment 6 Wolfgang Bauer 2016-08-19 17:28:23 UTC
Yes, for SSH ktelnetservice5 runs "konsole --noclose -e ssh -l username host -p port" (if a username or port is not specified, the corresponding option is omitted),
So this is indeed likely the same issue.

ktelnetservice5 does take the default terminal application from systemsettings though, so you could also change that to xterm as work-around.
Comment 7 Wolfgang Bauer 2016-08-19 21:56:36 UTC
*** Bug 367588 has been marked as a duplicate of this bug. ***
Comment 8 Stéphane Cachemaille 2016-09-01 15:24:17 UTC
I don't know if it's related. 
but on manjaro (arch derivative) since konsole 16.08 octopi (graphical package installer) don't work when it call terminal to install AUR package. seems konsole don't start correctly.
and also someone reported that his shortcut was not working anymore.

downgrading konsole to 16.04 solve the problem.

https://forum.manjaro.org/t/unstable-update-2016-08-30-networkmanager-haskell-plasma-5-7-4/8371/37
Comment 9 Jim Jones 2016-09-10 11:58:26 UTC
commands like 

"konsole -e mpv --fs /mnt/foo.avi also don't work"

--fs is used by konsole and i get Unknown option 'fs'.
although konsole -e "mpv --fs /mnt/foo.avi" is working.

Another combination that doesnt work are spaces inside filenames until they spaces are escaped.

konsole -e "mpv /mnt/data/foo\ 1.mp4" - works
konsole -e "mpv /mnt/data/foo 1.mp4" - doesn't work

please get this fixed and provide the functionality descibed in the help output:

Options: ... -e <cmd> Command to execute. This option will catch all following arguments, so use it as the last option.
Comment 10 Rex Dieter 2016-09-17 14:36:51 UTC
Marking confirmed.

Another side-effect is that application desktop shortcuts that include
Terminal=true
no longer work either (see also bug #368949)
Comment 11 Rex Dieter 2016-09-17 14:47:38 UTC
appears to be a consequence of porting away from kdelibs4support, which provided support for a plethora of extra command line options, including:
-caption (see bug #368949)
Comment 12 Kevin Kofler 2016-09-17 18:11:27 UTC
It's not the same regression (but likely also a consequence of the port): Here, we DON'T want to have -c parsed by Konsole at all, it should be treated as an argument to -e.

This breaks at least the debuginfo-install.sh from kdelibs4.
Comment 13 Kevin Kofler 2016-09-17 20:11:25 UTC
> This breaks at least the debuginfo-install.sh from kdelibs4.

From kde(4)-runtime's DrKonqi, actually.
Comment 14 Antonio Rojas 2016-09-19 10:12:24 UTC
*** Bug 369040 has been marked as a duplicate of this bug. ***
Comment 15 Antonio Rojas 2016-09-24 18:48:29 UTC
*** Bug 368899 has been marked as a duplicate of this bug. ***
Comment 16 Wolfgang Bauer 2016-09-24 21:33:33 UTC
*** Bug 369297 has been marked as a duplicate of this bug. ***
Comment 17 Antonio Rojas 2016-09-25 13:02:40 UTC
*** Bug 369314 has been marked as a duplicate of this bug. ***
Comment 18 Tobias Hunger 2016-10-25 08:06:44 UTC
Indeed the command line parsing of konsole is broken. It parses any option passed after -e as its own. E.g. "konsole -e echo --authors" makes konsole dump the list of its authors.
Comment 19 Christian González 2016-11-24 17:57:31 UTC
Will this bug be fixed before 16.12 (currently in beta) releasing? Or we will have to wait to 17.04 (or beyond)?
Comment 20 Jonathan Marten 2016-12-13 20:37:55 UTC
The cause appears to be a shortcoming in QCommandLineParser in that it has no option syntax for "capture all the remaining arguments after this one", as was the case for KCmdLineArgs and an option starting with '!'.  Some of the required functionality can be restored by setting the parser to not parse options after the first non-option argument:

--- a/src/main.cpp
+++ b/src/main.cpp
@@ -109,6 +109,7 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char* argv[])
 
     QSharedPointer<QCommandLineParser> parser(new QCommandLineParser);
     parser->setApplicationDescription(about.shortDescription());
+    parser->setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments);
     parser->addHelpOption();
     parser->addVersionOption();
     about.setupCommandLine(parser.data());

but which still fails if the first option after the command name is an option:

konsole --hold -e ls -l main.cpp           => error "Unknown option 'l'."

The workaround is to ensure that the first argument is not an option:

konsole --hold -e ls main.cpp -l           => works

which only works if the command accepts options after non-option arguments; alternatively

konsole --hold -e ls -- -l main.cpp        => works
Comment 21 Wolfgang Bauer 2016-12-14 11:39:32 UTC
(In reply to Jonathan Marten from comment #20)
> Some of
> the required functionality can be restored by setting the parser to not
> parse options after the first non-option argument:

Yes, but this requires Qt 5.6 at least.
Probably not a problem for KDE Applications 17.04, but it will prevent distributions that still use Qt 5.5 to backport the fix (I don't know if any of them ship konsole 16.08 though).

> The workaround is to ensure that the first argument is not an option:

Another workaround would be to make the '-e' option not take any arguments at all, then the actual command would be the first positional argument. (disadvantage: QCommandLineParser will not complain if there is no command at all after '-e', and the command itself may not start with a '-' but that can be ignored I suppose)

Another way I see to fix the problem is to parse the command line manually before handing it over to QCommandLineParser, and strip off '-e' and all that follows (and handle it manually).

Actually I experimented myself with both a bit already, but had no time yet to get it into a fully working shape...
Comment 22 OndraK 2016-12-22 10:56:10 UTC
Hello,

don't know if my problem is related to this bug, but might be:

Reproducible: always

Steps to reproduce:
1. define global shortcut, e.g., Win+v in systemsettings > global shortcuts, that would run command 'konsole -e vim' (w/o single quotes)
2. use Win+v to launch vim in konsole
3. start another instance of konsole (not tab), either A-F2, launch menu, quick launch widget

Actual result:
konsole is started with vim launched; Works with mc, ncmpcpp. When I go to 'Edit current profile', 'Command' field in 'General' tab does state 'vim' instead of full path to shell executable

Expected result:
Having konsole launched with shell only

Running konsole 16.08.3-r1

However, when the command is 'konsole --name Vim -e vim', next konsole I start works fone. So, this problem can be at least work-arounded :)

Thank you all who have ever worked on KDE :)
Comment 23 Wolfgang Bauer 2016-12-22 16:01:36 UTC
(In reply to OndraK from comment #22)
> Steps to reproduce:
> 1. define global shortcut, e.g., Win+v in systemsettings > global shortcuts,
> that would run command 'konsole -e vim' (w/o single quotes)
> 2. use Win+v to launch vim in konsole
> 3. start another instance of konsole (not tab), either A-F2, launch menu,
> quick launch widget
> 
> Actual result:
> konsole is started with vim launched; Works with mc, ncmpcpp. When I go to
> 'Edit current profile', 'Command' field in 'General' tab does state 'vim'
> instead of full path to shell executable

This rather sounds like bug#371863 (and its duplicates), which should be fixed in 16.12.0.

Btw, regarding *this* bug, somebody proposed a patch, which I can confirm is fixing the problems with the '-e' parameter:
https://git.reviewboard.kde.org/r/129677/
Comment 24 Jim Jones 2016-12-22 17:32:49 UTC
> Btw, regarding *this* bug, somebody proposed a patch, which I can confirm is
> fixing the problems with the '-e' parameter:
> https://git.reviewboard.kde.org/r/129677/

thanks, it works for me too
Comment 25 Alex Bikadorov 2017-01-07 20:37:07 UTC
*** Bug 374625 has been marked as a duplicate of this bug. ***
Comment 26 Adam 2017-01-28 01:23:53 UTC
Also prevents usage of konsole as a terminal in QtCreator when parameters are present.
Comment 27 Wolfgang Bauer 2017-01-28 11:35:55 UTC
The fix has been committed yesterday:
https://cgit.kde.org/konsole.git/commit/?id=a779c8314a7d27bb4691c220f793540e6f84f6c9