In POSIX, there is the fork()
function to create a sub-process. How can I achieve fork()
's functionality in Windows?
To start a new process, or in other words, a new subprocess in Python, you need to use the Popen function call. It is possible to pass two parameters in the function call. The first parameter is the program you want to start, and the second is the file argument.
Windows Constants (Flags) IMO, subprocess is more POSIX friendly, there are functions are only supporting on Unix environment. If you want to achieve some similar features on Windows, you may need to read through what Flags available for you.
To capture the output of the subprocess. run method, use an additional argument named “capture_output=True”. You can individually access stdout and stderr values by using “output. stdout” and “output.
A subprocess is a task that is created by a process to complete a task within the parent process. Let's expand on that; a process is a task performed by the program during its execution. In many, if not all cases, processes usually have smaller tasks that need to be completed before the process can end.
There is no direct equivalent of fork()
on Windows.
CreateProcess()
is the native function that can be used to create a new process (but, again, the semantics are rather different to fork()
's).
To put this another way, on Unix it is possible for a process to cheaply create a clone of itself. There is no inexpensive way to do this on Windows.
If you don't care about the cloning aspect of fork()
, then CreateProcess()
should do just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With