What I want to do is have a python script (that’s a python IRC bot) that can run another python script in the background/separately.
I could do something like this:
#irc codey stuff here...
if x == y:
os.system('s%\stuff.py') % path
But this would stop main.py and it then runs stuff.py (in 1 command prompt) which I don’t want to do.
So what I am trying to make this script do is when the IRC bot picks up a command via IRC, I want it to run stuff.py separately, like double clicking on stuff.py and having main.py and stuff.py running at the same time.
If there is a separate way of doing this in windows/linux, please, can you show both?
To spawn a background process, use the Popen class in the subprocess module.
Example:
After this
processis a process object that can be used to kill the process, wait for it to finish, communicate with it etc. If you just want to spawn the process and forget about it, you don’t need to keep the return value from Popen.