Python: fork, pipe and exec

前端 未结 3 1903
天命终不由人
天命终不由人 2021-01-03 02:47

I want to execute a program in a python application, it will run in the background but eventually come to the foreground.

A GUI is used to interact with it. But con

3条回答
  •  走了就别回头了
    2021-01-03 02:59

    That is not much complex in structure to build !

    Check this example

    if os.fork():
        os._exit(0)
        os.setsid()
        os.chdir("/")
        fd = os.open("/dev/null", os.O_RDWR)
        os.dup2(fd, 0)
        os.dup2(fd, 1)
        os.dup2(fd, 2)
    if fd 2:
        os.close(fd)
    

    This python code sets an id, changes the dir, opens a file and process and close !

提交回复
热议问题