This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Command line on Konsole to open a document with KWrite?

Tags: None
(comma "," separated)
solardde
Registered Member
Posts
8
Karma
0
Hello,

By a command line, I would like to have Konsole tell KWrite to open a document foo.htm, whose default application is not KWrite. I tried many different command statements. However, none of them worked right. Please help. I use KDE 3.5.10.


kwrite foo.htm
# KWrite opens foo.htm indeed.
# However, when the shell (Konsole) quits,
# the shell automatically terminates KWrite.
# I want KWrite and foo.htm to stay open
# even after the shell quits.
# It seems that the shell starts KWrite
# as a subprocess (or child process) of the shell,
# which is not what I want.


kwrite foo.htm &
# The ampersand (&) indicates a background job.
# KWrite opens foo.htm indeed.
# However, when the shell (Konsole) quits,
# the shell automatically terminates KWrite.
# I want KWrite and foo.htm to stay open
# even after the shell quits.


exec /usr/bin/kwrite foo.htm
# KWrite opens foo.htm indeed.
# However, when the shell (Konsole) quits,
# the shell automatically terminates KWrite.
# I want KWrite and foo.htm to stay open
# even after the shell quits.
#
# The exec command makes also the reverse
# undesirable for my purpose.
# When the document closes or when KWrite quits,
# the shell automatically terminates itself.
# I want the shell (Konsole) to stay open
# after KWrite quits.'
#
# I want the shell (Konsole) and KWrite
# to be independent of each other.


kfmclient exec /usr/bin/kwrite
# KWrite stays open even after
# the shell (Konsole) quits.
# However, this command statement opens
# only KWrite without the document foo.htm.
# I want foo.htm to be opened with KWrite.


kfmclient exec foo.htm
# foo.htm opens with Konqueror but not with KWrite.
# I want foo.htm to open with KWrite.
# I do not want to modify file associations.
# I want to keep Konqueror as the default
# application for foo.htm.


kfmclient exec /usr/bin/kwrite foo.htm
# The command fails with the following error message.
### kio (KMimeType): WARNING:
### KServiceType::offers :
### servicetype foo.htm not found


How can I overcome the above issues? Please show me a command statement that, from Konsole, opens a document with KWrite with the following features.

- Even after Konsole quits, KWrite and the document stay open.
- Even if the default application associated with the document is not KWrite, the command opens the document with KWrite.

The behavior that KWrite automatically quits when the shell quits indicates that the shell starts KWrite as a subprocess (or child process) of the shell. I guess that kfmclient can somehow start KWrite independently of the shell but not as a subprocess of the shell. However, I do not know how to make kfmclient open a document with KWrite if KWrite is not the default application of the document. How can one ask kfmclient to do so?

Or, more fundamentally, how can a process be started from a shell and not be a subprocess of the shell?

Many thanks in advance.


P.S. I may have to take a look at the source code of kfmclient (assuming that the source is open). Where is the source code of kfmclient on this site?
User avatar
TheBlackCat
Registered Member
Posts
2945
Karma
8
OS
Have you tried:

kfmclient exec `/usr/bin/kwrite foo.htm`

That quote symbol is supped to be the one you get with shift+~ or shift+(the key to the left of "1"). So not the quote symbol to the right of L


Man is the lowest-cost, 150-pound, nonlinear, all-purpose computer system which can be mass-produced by unskilled labor.
-NASA in 1965
solardde
Registered Member
Posts
8
Karma
0
TheBlackCat suggested the following line:
kfmclient exec `/usr/bin/kwrite foo.htm`


Thanks for the suggestion, but the backtick pipe `` does not work, either.

Before kfmclient receives anything from the backtick pipe, the shell executes the statement inside the backticks first. Thus, before kfmclient takes any action, the same thing as my first command statement in my original post happens.

In other words, before kfmclient takes any action, the following course of events happen. First, the document opens with KWrite, and the shell (Konsole) pauses while KWrite is running. Second, when the shell quits, KWrite automatically quits and the document closes. In this second event, the call to kfmclient gets automatically cancelled before kfmclient has any opportunity to act. And, nothing happens any further.

The second event can take another option. If I dismiss KWrite and the document while the shell is still pausing, then the shell resumes, and the "Run Command" dialog pops up, asking, "Enter the name of the application you want to run or the URL you want to view", with the Command field blank. Then, I have to type "/usr/bin/kwrite foo.htm" into the Command field, and has to click the Run button. Then, the document opens with KWrite again. This time after the Run Command, KWrite and the document stay open even after the shell quits. However, this method generates too much user-interaction after the command on the shell, and hence defeats the purpose.

Depending on whether Konsole quits before KWrite or the latter quits before the former, the method of backtick pipe ends up with two different results. Nevertheless, both of the results are undesirable.
solardde
Registered Member
Posts
8
Karma
0
I have found a solution on my own.

kshell /usr/bin/kwrite foo.htm
# opens foo.htm with KWrite.
# KWrite and foo.htm stay open
# after the shell (Konsole) quits.
# The shell stays open after KWrite quits.

kshell kwrite foo.htm
# works the same as above.


By the way, none of the following works.

man kshell
help kshell
info kshell
kshell -h
kshell --help
kshell --commands

I would like some information about kshell such as syntax, options and description. Thanks.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
kshell is part of KDE 3, and is thus no longer supported.

The correct method to do this is to invoke KLauncher.

Code: Select all
qdbus org.kde.klauncher /KLauncher exec_blind /usr/bin/kwrite /full/path/to/file.htm


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
solardde
Registered Member
Posts
8
Karma
0
bcooksley wrote:

! kshell is part of KDE 3, and is thus no longer
! supported.
! The correct method to do this is to invoke
! KLauncher.
!
! qdbus org.kde.klauncher /KLauncher exec_blind \
! /usr/bin/kwrite /full/path/to/file.htm
!

I use KDE 3.5.10, as I mentioned in the original post. By "KDE 3", did you mean KDE 3.x.x (including 3.5.10) as opposed to KDE 4.x.x? Or, did you mean KDE 3.0.x as opposed to 3.5.x?

I tried, on KDE 3.5.10, the qdbus statement you suggested. I got an error, "qdbus: command not found". To use qdbus, is KDE 4.x.x required?

Without qdbus, is KLauncher unreachable? I tried the following, which ended up with an error.

klauncher /usr/bin/kwrite foo.htm
# returns the following error message
### klauncher: This program is not supposed
### to be started manually.
### klauncher: It is started automatically
### by kdeinit.


On KDE 3.5.10, should I stick with the kshell statement that I presented in the 4th post?

kshell /usr/bin/kwrite foo.htm
# opens foo.htm with KWrite.
# KWrite and foo.htm stay open
# after the shell (Konsole) quits.
# The shell stays open after KWrite quits.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
The steps I gave apply to KDE 4 only. The same method should be reachable using dcop on KDE3, which is probably what kshell does.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
solardde
Registered Member
Posts
8
Karma
0
bcooksley presented a qdbus statement for KDE 4:

! qdbus org.kde.klauncher /KLauncher exec_blind \
! /usr/bin/kwrite /full/path/to/file.htm

When he realized that I use KDE 3.5.10, bcooksley added:

! The same method should be reachable using dcop on KDE3
!


Could you show me the exact command line using "dcop" to have klauncher execute "/usr/bin/kwrite /foo.htm"?


By simply replacing qdbus with dcop, I tried the following, which failed.

dcop org.kde.klauncher /KLauncher exec_blind \
/usr/bin/kwrite /foo.htm
# returns the following error message
### object not accessible


Next, I opened the GUI program kdcop (as opposed to the command line program dcop) to learn applications, interfaces and methods available for DCOP. Then, I tried the following command line statement on Konsole.

dcop klauncher klauncher exec_blind \
/usr/bin/kwrite /foo.htm
# returns the following error message
### Not enough arguments (expected 2, got 2).

"expected 2, got 2" sounds good enough. I do not understand what is wrong.


By the way, I twiddled with kdcop (GUI) by trial and error.

kdcop > klauncher > klauncher (default) > void exec_blind(QCString, QValueList<QCString>)

For the first QCString, I entered /usr/bin/kwrite. For QValueList<QCString>, I entered the full pathname of the document to be opened. However, kdcop and/or klauncher automatically threw away the first four characters of the pathname for unknown reason. Therefore, in front of the pathname, I put four arbitrary characters such as four white spaces or just "aaaa". This workaround turned out successful. How come kdcop and/or klauncher cut(s) off the first four characters in QValueList?


Even though I managed to have kdcop (GUI) open the document with KWrite via klauncher, I am still unable to have dcop on Konsole do the job. Please show me the exact command line using dcop and klauncher to open the document with KWrite.

Many thanks in advance.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Not sure what the exact syntax is, but if you run "dcop | grep -i klauncher" it should show the next argument to add.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Komplicated
Registered Member
Posts
5
Karma
0
OS
How about just `/usr/bin/kwrite foo.htm`? That is the backtick solution without kfmclient. Seems to work for me on kde 4.4.
offer8008
Registered Member
Posts
1
Karma
0
To run klauncher exec_blind:
Just key in like below:
dcop klauncher klauncher exec_blind /usr/bin/kwrite a a a a a
solardde wrote:bcooksley presented a qdbus statement for KDE 4:

! qdbus org.kde.klauncher /KLauncher exec_blind \
! /usr/bin/kwrite /full/path/to/file.htm

When he realized that I use KDE 3.5.10, bcooksley added:

! The same method should be reachable using dcop on KDE3
!


Could you show me the exact command line using "dcop" to have klauncher execute "/usr/bin/kwrite /foo.htm"?


By simply replacing qdbus with dcop, I tried the following, which failed.

dcop org.kde.klauncher /KLauncher exec_blind \
/usr/bin/kwrite /foo.htm
# returns the following error message
### object not accessible


Next, I opened the GUI program kdcop (as opposed to the command line program dcop) to learn applications, interfaces and methods available for DCOP. Then, I tried the following command line statement on Konsole.

dcop klauncher klauncher exec_blind \
/usr/bin/kwrite /foo.htm
# returns the following error message
### Not enough arguments (expected 2, got 2).

"expected 2, got 2" sounds good enough. I do not understand what is wrong.


By the way, I twiddled with kdcop (GUI) by trial and error.

kdcop > klauncher > klauncher (default) > void exec_blind(QCString, QValueList<QCString>)

For the first QCString, I entered /usr/bin/kwrite. For QValueList<QCString>, I entered the full pathname of the document to be opened. However, kdcop and/or klauncher automatically threw away the first four characters of the pathname for unknown reason. Therefore, in front of the pathname, I put four arbitrary characters such as four white spaces or just "aaaa". This workaround turned out successful. How come kdcop and/or klauncher cut(s) off the first four characters in QValueList?


Even though I managed to have kdcop (GUI) open the document with KWrite via klauncher, I am still unable to have dcop on Konsole do the job. Please show me the exact command line using dcop and klauncher to open the document with KWrite.

Many thanks in advance.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]