1

I got a simple run-until-terminated service. At the end of it, once all threads are started, it has something like input('Press something to terminate the program.'). Now I want it to be called with few other services in a single chain like python myservice.py && python myanotherservice.py. Because of input(...) it waits for user to reply at the time python service.py is executed. Is there a way to redirect stdin to some special place that can never be read? Or what's the better way?

P.S. Yeah, I use Python, input method. Yet it shouldn't matter.

P.S.S. I don't care about termination remotely: service gonna die with entire VPS, so it's fine to be unable to terminate it once started.

Zazaeil
  • 3,900
  • 2
  • 14
  • 31
  • Break down your question so its more readable. – Poojan Oct 04 '19 at 19:34
  • It's called "daemon mode" - the program exits to shell but leaves a part of it running. Definitely should not be done with input from `stdin`, but I don't know how. I added this comment to clarify what's being asked. – anatolyg Oct 04 '19 at 19:37
  • I don't think you want the `input()` prompt at all. It sounds like you want a daemon program that runs in the background. See the linked question(s) for help making a daemon in Python. – John Kugelman Oct 04 '19 at 19:38
  • @JohnKugelman, yeah, that service wasn't created with automation in mind. – Zazaeil Oct 04 '19 at 19:39
  • Is this your Python script or a third party one you can't touch? If it's yours, use `python-daemon` to daemonize it. If you can't change it, you'll need to daemonize it from the outside. If it's the latter let me know and I'll change the duplicate question list. – John Kugelman Oct 04 '19 at 19:42
  • I can change it once write access will be granted, thanks. – Zazaeil Oct 04 '19 at 21:49

1 Answers1

-3

You could use a pipe :

echo | python myservice.py

This would supply an answer to the input and let the program continue.

user803422
  • 2,636
  • 2
  • 18
  • 36