How can I run a process in a terminal window and then hide that window?

10,901

Solution 1

IMHO, the optimal solution is to run that proxy as system daemon.

This tutorial from Novel should teach you core concepts. Unluckily it is a little bit SuSE-centric, on other distributions the details could be slightly different. Use it as starting point.

P.S. There is something strange in your question, a service started at boot doesn't have a terminal window. A program started when you log on can have a terminal window. Perhaps do you have auto-login feature enabled, so you are confusing boot process with log-in process.

Solution 2

Using tmux you can start a detached process, which is effectively "hidden", and attach it to check its status, as and when you like. If you start it from a terminal, you can even close that terminal session, and subsequently attach to your tmux python process from another terminal ...

This example uses watch as the command to run, but just substitute your python command... It starts the tmux session in an already deteched state.

tmux new -d 'watch -n 1 -d date'

To view the current state of the "hidden" (detached) session, just type tmux attach in a Terminal window...

You can also use screen, but I believe tmux may be the better choice, based on the comments in this Unix-&-Linux answer...

Solution 3

A more rough approach is to write a simple script that wraps your program and detaches it from its terminal. Something like:

#!/bin/bash

nohup python ~/program/proxy.py > ~/.proxy.log 2>&1 &

Then you can put it in your log-in auto-startup sequence (as you, probably, already done).

Solution 4

To provide you a literal answer to your question, you could use a program such as AllTray*. You could then pass it a command to start up a terminal, and pass a command to that terminal to run your program. If you tell AllTray to hide the terminal, then it will be embedded in the system tray, ready for you to pull up if you need to view the output.

However, I would recommend you go with andcoz's answer and run this program as a system dæmon. Have the output go to a log file. The only way that wouldn't work is if it were an interactive program, but by the sounds of it, we're not talking about an interactive program.

* Disclaimer: I am the maintainer of AllTray

Share:
10,901

Related videos on Youtube

ufo22940268
Author by

ufo22940268

Updated on September 18, 2022

Comments

  • ufo22940268
    ufo22940268 over 1 year

    I want to run python ~/program/proxy.py in a terminal when I boot up. And then hide this terminal window (because it is just a proxy program, and I don't want to see the debug info). So how can I get it to work?

    • tcoolspy
      tcoolspy over 12 years
      As @andcoz notes, there is something wrong here. Running a python program as part of the boot process would not generate a terminal window in the first place. In fact even if it was part of the login/session script it shouldn't need a terminal window. Can you edit your question to show how exactly you have configured this NOW so it's more clear what needs to be changed to accomplish what you are after?
  • chrishollinworth
    chrishollinworth over 12 years
    The posix nohup does not call setsid() (some implementations do) you've only isolated the signal, it's still in the same process group
  • serb
    serb over 12 years
    Yes, @symcbean, you are right. Obviously, I prefer my other answer. This answer is only a quick and rough alternative. It also do not take in account that if you log out and then (re)log in, you'll run two instances of the proxy.
  • chrishollinworth
    chrishollinworth over 12 years
    agreed writing a daemon would be a better approach, but 'echo /usr/bin/python ~/program/proxy.py | at now' is a quick fix.