2

For closing terminal without killing script/command we use & operator at last while calling command. Like:

gedit &

Here I used gedit as an example command

Same thing I want to do on another terminal (from current terminal). I am using following command(s) to run script/command onto another terminal:

  • gnome-terminal -e 'gedit'
  • gnome-terminal -x bash -c 'gedit'

But here if I close new opened terminal, then script/program runnung by [command] also killed. So I've tried using & as follows:

  • gnome-terminal -e 'gedit' &
  • gnome-terminal -x bash -c 'gedit' &

But none of above is working.

So, How can I achieve this : From current gnome-terminal, Execute command in another gnome-terminal and close that (new-opened) terminal after launching command without killing running command.

0

3 Answers 3

3

You can use nohup command - it disconnects the process from the terminal, so even if you close the gnome-terminal window, it will continue to run.

Example: gnome-terminal -e "nohup bash gedit"

2
  • Yes this command is working, But I've to manually close new opened gnome-terminal window. I want that it will be automatically closed after launching command (gedit).
    – Pandya
    Jan 12, 2015 at 12:24
  • Than you for suggesting nohup that will help me to solve my problem and I write answer
    – Pandya
    Jan 12, 2015 at 12:44
1

You can user screen utility. Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells - for more details execute man screen.

As soon as you execute the screen command in the shell a new window with a shell in it will be created. You can execute whatever command/script/daemon you want. You can easily detach from the window using the key shortcut: Ctrl+A+D.

To list all sessions you have started you can use screen -list. You can attach to the lastly detached session using screen -r or if you want to attach on a particular session use screen -r <host.tty>.

Example:

[root@dns-ldap ~]# screen -list
There are screens on:
        5708.pts-0.dns-ldap     (Detached)
        5648.pts-0.dns-ldap     (Detached)
        5725.pts-0.dns-ldap     (Detached)
3 Sockets in /var/run/screen/S-root.

[root@dns-ldap ~]# screen -r 5708.pts-0.dns-ldap #this will attach you to terminal 5708.pts-0.dns-lda. I have detached from the terminal usinc Ctrl+A+D
[detached]
[root@dns-ldap ~]# screen -r 5648.pts-0.dns-ldap
[detached]
[root@dns-ldap ~]#
1
  • Your screen command also help me to find answer
    – Pandya
    Jan 12, 2015 at 12:46
0

Combining nohup & screen, Al last I achieved what I want.

By kirill-a, the command : gnome-terminal -e "nohup bash gedit" is suggested.

However by using above command, I can run command and can close new opened gnome-terminal without killing running command, BUT I've to manually close new opened gnome-terminal window. And I want it to be closed automatically after launching command.

By Dimitar Dimitrov screen command is suggested.

At-last I used screen with nohup and my Final command becomes:

  • gnome-terminal -e 'screen nohup gedit'

  • gnome-terminal -x bash -c 'screen nohup gedit'

By using either of above command(s) I get: command launched in new terminal window and after launching command, new opened terminal closed without killing running command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .