2

I tried below code to run my subprocess after 1 minute

 process =  Popen(['python3','helloworld.py','|','at -m now +1 minute'], stdout=PIPE, stderr=PIPE)

I run above line from terminal..it is executing immediately but not after 1 minute. How to set a particular time to RUN..
how to run subprocess at a given time python.
Please help me.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • duplicate of https://stackoverflow.com/questions/15088037/python-script-to-do-something-at-the-same-time-every-day – Benjamin Mar 27 '18 at 09:24
  • While part of me agree with @Benjamin, that this is a duplicate of the above question, I still consider the approach above somewhat unique in that it is a part of a Python program (a subprocess) that shall run at a certain time. That is not exactly the same, although similar. – JohanL Mar 27 '18 at 13:29
  • Note that the `bash` command given will **not** delay the execution of the subprocess, only it's output. To actually delay the execution, the `at` command must be the first command in the pipe. I would say there are better ways to do it in Python, though. – JohanL Mar 27 '18 at 13:37

1 Answers1

0

You can't use pipe in command unless you set shell=True with Popen.

process =  Popen('"python3 helloworld.py" | at -m now +1 minute', stdout=PIPE, stderr=PIPE, shell=True)
Yassine Faris
  • 951
  • 6
  • 26
  • when i print stderr it is showing like "commands will be executed using /bin/sh\njob 26 at Tue Mar 27 10:19:00 2018(time after 1 minute)" But it is still execcuting Immediately...... – Srujan Kumar Mar 27 '18 at 10:29
  • getting same issue...executing immediately ...not after 1 minute – Srujan Kumar Mar 27 '18 at 11:11