How to asynchronously launch a GUI application from command line?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
benev4131
Level 1
Level 1
Posts: 14
Joined: Thu Oct 07, 2021 7:04 pm

How to asynchronously launch a GUI application from command line?

Post by benev4131 »

From command line on terminal, I would like to asynchronously launch a GUI application.

Code: Select all

xed

Code: Select all

xed f.txt
The above first command launches the GUI text editor "Xed". The second command opens a text file "f.txt" with "Xed". However, unfortunately, both commands launch "Xed" synchronously. By "synchronous", I mean the following. As soon as it launches Xed, the command stalls and waits forever for the user to quit the Xed application. If the command is forcefully terminated by Control+C, then Xed will also be forcefully terminated.

I want to launch it asynchronously. That is, I do not want the command to wait for the GUI application to quit. Once the command launches the GUI application, I want the command to leave the GUI application alone.

By the way, if the Xed application is already open, then executing `xed` on command line opens asynchronously a second tab in the Xed window without waiting for the Xed application to quit.

The situation is the same on both Mint 20.2 MATE and Mint Cinnamon.

The situation is also the same on Ubuntu MATE. `pluma` on command line on Ubuntu MATE launches the text editor "Pluma" synchronously.

Thank you in advance.


---- Update ----

My words were insufficient when I initially wrote the original post, but I now realize that I have to add two more conditions:

- I want the GUI application to stay alive when Terminal is closed.

- As soon as the GUI application is launched, I want the shell prompt to come back and be ready for other commands such as `cd`, `ls -l`, `echo` and so on.

The Xed application launched by `xed &` will be forcefully terminated when the Terminal window (on which `xed &` was executed) is closed.

After `nohup xed &` is issued, nohup lingers forever on Terminal, and prevents the shell prompt from coming back.

Thank you in advance.

----
Note about notation: When I write like `xed &` in text, the backtick quotes are NOT part of the command. I would use $() for command substitution.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
waitabit
Level 2
Level 2
Posts: 65
Joined: Tue Aug 25, 2015 11:04 am

Re: How to asynchronously launch a GUI application from command line?

Post by waitabit »

You can launch it asynchronously this way:

Code: Select all

xed &
If you forgot to add the '&' and launched it syncronously, you can move it to the background by pressing Ctrl+z.
Kester
Level 5
Level 5
Posts: 504
Joined: Sat Apr 30, 2016 3:05 pm

Re: How to asynchronously launch a GUI application from command line?

Post by Kester »

Hi,

I was interested in benev4131's post so tried opening various applications including xed via the terminal (my system is Mint 20.2 XFCE) but whatever I tried I would get a dbind warning as in the example below:

(xed:18193): dbind-WARNING **: 15:10:33.863: Couldn't register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

I don't know if your suggestion, waitabit, worked for benev4131 but when I tried it, I still got the same error. The program, both with and without the '&' typed in the terminal, will run and can be saved successfully but closing the terminal closes the program so if unsaved, the work is lost.

Cheers.
User avatar
karlchen
Level 23
Level 23
Posts: 18228
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: How to asynchronously launch a GUI application from command line?

Post by karlchen »

Kester wrote: Thu Oct 28, 2021 10:21 ambut closing the terminal closes the program so if unsaved, the work is lost.
Linux Mint 19.3 Cinnamon. Gnome-terminal application.
Launched xed &, typed something in xed, just some irrelevant. Then closed the terminal application. xed is still loaded and usable.
Next try:
Launched xed, without detaching it from the gnome-terminal application. Again typed something in xed, just some irrelevant. Closed the terminal application and xed was gone, too, indeed.
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 792 days now.
Lifeline
waitabit
Level 2
Level 2
Posts: 65
Joined: Tue Aug 25, 2015 11:04 am

Re: How to asynchronously launch a GUI application from command line?

Post by waitabit »

Kester wrote: Thu Oct 28, 2021 10:21 am but closing the terminal closes the program
The original question was about detaching xed from the command line, not the terminal. To achieve also the latter, you can use the 'nohup' command to launch xed.

Code: Select all

nohup xed &
Then you can close the terminal, leaving xed running on its own.
Kester
Level 5
Level 5
Posts: 504
Joined: Sat Apr 30, 2016 3:05 pm

Re: How to asynchronously launch a GUI application from command line?

Post by Kester »

Thanks waitabit and karlchen.

Using the command 'nohup xed &' in the terminal allowed me to open the program however I did get a warning as follows: 'nohup: ignoring input and appending output to 'nohup.out' leaving the terminal hanging but closing the terminal did not close xed. I've a bit of learning to do about the differences between Terminal and Command Line but I don't want to hijack this thread so I will withdraw now and leave it to benev4131 and those who come to his aid. I will open a new thread if needed later.

Cheers.
mikeflan
Level 17
Level 17
Posts: 7155
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: How to asynchronously launch a GUI application from command line?

Post by mikeflan »

I am on LM 19.3.
xed rt.txt & works perfectly. Very nice.
nohup xed rt.txt & gives the nohup error mentioned above and ties up the terminal just like if I had done xed rt.txt
waitabit
Level 2
Level 2
Posts: 65
Joined: Tue Aug 25, 2015 11:04 am

Re: How to asynchronously launch a GUI application from command line?

Post by waitabit »

mikeflan wrote: Thu Oct 28, 2021 9:55 pm the nohup error mentioned above
It's not an error, just information. What it means, you can see via the 'nohup --help' command. As for the terminal being tied up, if by that you mean it doesn't show the command line prompt, just press Enter to bring it back.
benev4131
Level 1
Level 1
Posts: 14
Joined: Thu Oct 07, 2021 7:04 pm

Re: How to asynchronously launch a GUI application from command line?

Post by benev4131 »

My words were insufficient when I initially wrote the original post, but I now realize that I have to add two more conditions:

- I want the GUI application to stay alive when Terminal is closed.

- As soon as the GUI application is launched, I want the shell prompt to come back and be ready for other commands such as `cd`, `ls -l`, `echo` and so on.

The Xed application launched by `xed &` will be forcefully terminated when the Terminal window (on which `xed &` was executed) is closed.

After `nohup xed &` is issued, nohup lingers forever on Terminal, and prevents the shell prompt from coming back.

Thank you in advance.

----
Note about notation: When I write like `xed &` in text, the backtick quotes are NOT part of the command. I would use $() for command substitution.
waitabit
Level 2
Level 2
Posts: 65
Joined: Tue Aug 25, 2015 11:04 am

Re: How to asynchronously launch a GUI application from command line?

Post by waitabit »

benev4131 wrote: Fri Oct 29, 2021 1:29 am After `nohup xed &` is issued, nohup lingers forever on Terminal
Not at all. Press Enter and the prompt will come up. For it to be already there, you can use a longer command:

Code: Select all

nohup xed &>/dev/null &
Actually this is the better way, since without the redirection to null, nohup will create files 'nohup.out' wherever you call it, and you probably don't need those files.

To shorten the command, you can create a function and put it in the file ~/.bash_aliases, for example. Something like:

Code: Select all

function nh { nohup "$@" &>/dev/null & }
Then you can call it like this:

Code: Select all

nh xed
Locked

Return to “Software & Applications”