I have a python program that runs command line (Windows 10), how can I save the output as a text file, also I want to run the command line process in background.
Asked
Active
Viewed 607 times
-1
-
I'd suggest checking the answer(s) to this question: https://stackoverflow.com/questions/4828885/how-to-direct-output-into-a-txt-file-in-python-in-windows – adamgy May 25 '20 at 03:15
-
1Does this answer your question? [how to direct output into a txt file in python in windows](https://stackoverflow.com/questions/4828885/how-to-direct-output-into-a-txt-file-in-python-in-windows) – adamgy May 25 '20 at 03:18
1 Answers
0
you can save the output of a command to a text file by simply typing > txtFile.txt
after your command, like:
dir > text.txt
and for your task to run in the background you should use Threads in python. example:
from threading import Thread
def do_in_background():
# your background task should be here.
pass
t = Thread(target=do_in_background, daemon=True)
t.start()

Ryan Norooz
- 1,358
- 1
- 12
- 8