我想在wget下载完成后运行一个PHP脚本。没问题,我可以用一些东西.
wget http://example.com && php script.php但!我使用wget (wget -b)的后台下载,它返回类似于Continuing in background, pid 12345的内容。
可以在后台运行wget并在下载?之后运行脚本。
谢谢你,齐纳
发布于 2016-08-27 04:19:42
当您使用wget选项时,命令在其他shell会话(塞西德)中创建子进程。初始进程在子进程启动后完成。
子进程在其他shell会话中运行,因此我们不能使用等待命令。但是我们可以编写一个循环来检查子进程是否正在运行。我们需要子进程的pid。
举个例子:
wget -b http://example.com && \
(
PID=`pidof wget | rev | cut -f1 | rev`;
while kill -0 $PID 2> /dev/null; do sleep 1; done;
) && \
php script.php &另一种获取子进程pid的方法是解析wget的输出。
另外,要了解wget的工作背景选项,可以查看C中的源代码:
...
pid = fork ();
if (pid < 0)
{
perror ("fork");
exit (1);
}
else if (pid != 0)
{
printf (_("Continuing in background, pid %d.\n"), (int)pid);
if (logfile_changed)
printf (_("Output will be written to `%s'.\n"), opt.lfilename);
exit (0);
}
setsid ();
freopen ("/dev/null", "r", stdin);
freopen ("/dev/null", "w", stdout);
freopen ("/dev/null", "w", stderr);
...https://stackoverflow.com/questions/39156583
复制相似问题