相关疑难解决方法(0)

使用PHP中的实时输出运行进程

我正在尝试在网页上运行一个将实时返回其输出的进程.例如,如果我运行'ping'进程,它应该在每次返回一个新行时更新我的​​页面(现在,当我使用exec(命令,输出)时,我被迫使用-c选项并等待进程完成以查看在我的网页上输出).有可能在PHP中这样做吗?

我也想知道当有人离开页面时,杀死这种过程的正确方法是什么.在"ping"过程中,我仍然可以看到系统监视器中运行的进程(有意义).

php linux apache real-time process

67
推荐指数
7
解决办法
8万
查看次数

subprocess:删除Windows中的子进程

在Windows上,subprocess.Popen.terminate调用win32 TerminalProcess.但是,我看到的行为是我尝试终止的进程的子进程仍在运行.这是为什么?如何确保进程启动的所有子进程都被终止?

python windows subprocess process kill-process

38
推荐指数
5
解决办法
2万
查看次数

在Python中实时更新可执行子流程控制台输出

我一直在阅读这个问题指出该问题提出的解决方案没有达到我要尝试的目的。这个想法类似于这个问题,但是我在这里给出一个更好的例子。

我需要在Python 3.7中构建一个GUI,以监视和控制用C编写的旧软件的执行。现在,我试图从Python调用一个简单的测试可执行文件,并将其打印在GUI上,但是现在在与python相同的控制台上打印就足够了。问题是可执行文件要花很长时间才能完全执行,但是同时打印控制台消息,我需要这些消息由GUI快速读取。

这是一个工作示例:

在Python 3.7中:

import sys
from threading import Thread
import time
import subprocess

class HandleTarget(Thread):
    def __init__(self):
        Thread.__init__(self)

    def run(self):
        subprocess.Popen(["hello.exe"], stdout=sys.stdout, bufsize=1)

class Printer(Thread):
    def __init__(self):
        Thread.__init__(self)

    def run(self):
        for i in range(1, 15):
            sys.stdout.write("Hi back ("+str(i)+")!\n")
            time.sleep(1.0)

thread_1 = HandleTarget()
thread_2 = Printer()

# Launching threads:
thread_1.start()
thread_2.start()
Run Code Online (Sandbox Code Playgroud)

现在,示例可执行文件(“ hello.exe”)可以在C中构建,如下所示:

#include <stdio.h>
#include <time.h>

int main() {
    struct timespec time;
    double tic = 0;
    double toc = 0;

    for( …
Run Code Online (Sandbox Code Playgroud)

executable console-application python-3.x

6
推荐指数
1
解决办法
283
查看次数