Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

A pain in the ass of major dimensions. -- C. A. Desoer, on the solution of non-linear circuits


devel / comp.lang.php / Re: proc_open, proc_get_status, proc_close

SubjectAuthor
* proc_open, proc_get_status, proc_closeBadarbo
+- Re: proc_open, proc_get_status, proc_closeArne Vajhøj
+- Re: proc_open, proc_get_status, proc_closeJ.O. Aho
+- ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Who's Identity Is A Very Big Secret
+- Re: proc_open, proc_get_status, proc_closeArno Welzel
`- Re: proc_open, proc_get_status, proc_closeV õ l u r

1
proc_open, proc_get_status, proc_close

<20230106112959.738fadea@gargantua.manuelito.lan>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=757&group=comp.lang.php#757

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!Q4PhrXgRgU8UdZF3HYlqNg.user.46.165.242.75.POSTED!not-for-mail
From: badarbo@TOGLITUTTELEMAIUSCOLEhotmail.it (Badarbo)
Newsgroups: comp.lang.php
Subject: proc_open, proc_get_status, proc_close
Date: Fri, 6 Jan 2023 11:29:59 +0100
Organization: Aioe.org NNTP Server
Message-ID: <20230106112959.738fadea@gargantua.manuelito.lan>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="8593"; posting-host="Q4PhrXgRgU8UdZF3HYlqNg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.36; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Badarbo - Fri, 6 Jan 2023 10:29 UTC

Hello,
with the code below, $rv is 0 :-)

--- begin code ---
$pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file','stderr.log','w']];
$proc=proc_open('sleep 3',$pdesc,$pipes);
fclose($pipes[0]);
$rv=proc_close($proc);
echo('rv: '.$rv.PHP_EOL);
exit(0);
--- end code ---

With the code below, $rv is -1 :-(

--- begin code ---
$pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file',stderr.log','w']];
$proc=proc_open('sleep 3',$pdesc,$pipes);
$done=false;
while ($done===false) {
$pstat=proc_get_status($proc);
if (!$pstat['running']) $done=true;
usleep(500000);
} fclose($pipes[0]);
$rv=proc_close($proc);
echo('rv: '.$rv.PHP_EOL);
exit(0);
--- end code ---

Why oh why?

Re: proc_open, proc_get_status, proc_close

<tp99vj$14t$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=758&group=comp.lang.php#758

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!LeVffQP25j5GAigzc2gaQA.user.46.165.242.75.POSTED!not-for-mail
From: arne@vajhoej.dk (Arne Vajhøj)
Newsgroups: comp.lang.php
Subject: Re: proc_open, proc_get_status, proc_close
Date: Fri, 6 Jan 2023 09:07:46 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tp99vj$14t$1@gioia.aioe.org>
References: <20230106112959.738fadea@gargantua.manuelito.lan>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="1181"; posting-host="LeVffQP25j5GAigzc2gaQA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Arne Vajhøj - Fri, 6 Jan 2023 14:07 UTC

On 1/6/2023 5:29 AM, Badarbo wrote:
> with the code below, $rv is 0 :-)
>
> --- begin code ---
> $pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file','stderr.log','w']];
> $proc=proc_open('sleep 3',$pdesc,$pipes);
> fclose($pipes[0]);
> $rv=proc_close($proc);
> echo('rv: '.$rv.PHP_EOL);
> exit(0);
> --- end code ---
>
> With the code below, $rv is -1 :-(
>
> --- begin code ---
> $pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file',stderr.log','w']];
> $proc=proc_open('sleep 3',$pdesc,$pipes);
> $done=false;
> while ($done===false) {
> $pstat=proc_get_status($proc);
> if (!$pstat['running']) $done=true;
> usleep(500000);
> }
> fclose($pipes[0]);
> $rv=proc_close($proc);
> echo('rv: '.$rv.PHP_EOL);
> exit(0);
> --- end code ---
>
> Why oh why?

When I read:

last comment in https://www.php.net/manual/en/function.proc-close.php

second comment in https://www.php.net/manual/en/function.proc-get-status.php

then one could get the idea that proc_get_status take the status
code for $pstat['exitcode'] and proc_close after that return -1.

Arne

Re: proc_open, proc_get_status, proc_close

<k1r0tsFb0lU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=759&group=comp.lang.php#759

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: proc_open, proc_get_status, proc_close
Date: Fri, 6 Jan 2023 17:35:08 +0100
Lines: 51
Message-ID: <k1r0tsFb0lU1@mid.individual.net>
References: <20230106112959.738fadea@gargantua.manuelito.lan>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net dZNd/JLEfGndb+wJdFVaBAuf8eH/uD94YFxc9kHWZipH5QU3JJ
Cancel-Lock: sha1:3JCgU6BDCd5Ei33cjpHhZhqTZoE=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-US-large
In-Reply-To: <20230106112959.738fadea@gargantua.manuelito.lan>
 by: J.O. Aho - Fri, 6 Jan 2023 16:35 UTC

On 06/01/2023 11.29, Badarbo wrote:

> With the code below, $rv is -1 :-(
>
> --- begin code ---
> $pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file',stderr.log','w']];
> $proc=proc_open('sleep 3',$pdesc,$pipes);
> $done=false;
> while ($done===false) {
> $pstat=proc_get_status($proc);
> if (!$pstat['running']) $done=true;
> usleep(500000);
> }
> fclose($pipes[0]);
> $rv=proc_close($proc);
> echo('rv: '.$rv.PHP_EOL);
> exit(0);
> --- end code ---
>
> Why oh why?
>
I guess it's as Arne already pointed out the second comment on
proc_get_status() that has deciphered the "The exit code returned by the
process (which is only meaningful if running is false). Only first call
of this function return real value, next calls return -1."
So as long as you don't try to get the status you will get it when you
run proc_close, if you use proc_get_status you will need to keep track
of the status code yourself by storing in a variable that you can access
when you execute proc_close, here is a simple fix where we have the
latest $pstat with the correct exit code:

--- start of file ---
$pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file','stderr.log','w']];
$proc=proc_open('sleep 3',$pdesc,$pipes);

do {
$pstat=proc_get_status($proc);
usleep(500000);
} while($pstat['running']);

fclose($pipes[0]);
$rv=proc_close($proc);
echo('rv: '.$rv.', exit code: '.$pstat['exitcode'].PHP_EOL);
--- eof ---

Keep in mind that if you have another "$pstat=proc_get_status($proc);"
any where between the end of the do-while loop and proc_close, then the
$pstat['exitcode'] would be -1 too.

--
//Aho

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

<3c3d18dc-7e7e-431b-9f9e-0192909dab0an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=760&group=comp.lang.php#760

  copy link   Newsgroups: comp.lang.php
X-Received: by 2002:ad4:548f:0:b0:50c:bbc4:12f7 with SMTP id pv15-20020ad4548f000000b0050cbbc412f7mr2250156qvb.87.1673050540251;
Fri, 06 Jan 2023 16:15:40 -0800 (PST)
X-Received: by 2002:a05:690c:ecf:b0:4ae:7fc2:6f2 with SMTP id
cs15-20020a05690c0ecf00b004ae7fc206f2mr1686141ywb.280.1673050540068; Fri, 06
Jan 2023 16:15:40 -0800 (PST)
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!news.szaf.org!fu-berlin.de!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.php
Date: Fri, 6 Jan 2023 16:15:39 -0800 (PST)
In-Reply-To: <20230106112959.738fadea@gargantua.manuelito.lan>
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.38.241; posting-account=ODZcTwoAAAA1dkd0WUQjhwbvDyYEiWdh
NNTP-Posting-Host: 82.131.38.241
References: <20230106112959.738fadea@gargantua.manuelito.lan>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3c3d18dc-7e7e-431b-9f9e-0192909dab0an@googlegroups.com>
Subject: ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
From: angel00000100000@icloud.com (Who's Identity Is A Very Big Secret)
Injection-Date: Sat, 07 Jan 2023 00:15:40 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
 by: Who's Identity - Sat, 7 Jan 2023 00:15 UTC

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

Re: proc_open, proc_get_status, proc_close

<k1tg26F6v07U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=761&group=comp.lang.php#761

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: proc_open, proc_get_status, proc_close
Date: Sat, 7 Jan 2023 16:05:44 +0100
Lines: 54
Message-ID: <k1tg26F6v07U1@mid.individual.net>
References: <20230106112959.738fadea@gargantua.manuelito.lan>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net OoNRLwOMpkWBtzW3Vg3viQnemEzeTrZ0IyYY0gbaGLe1bHwnWY
Cancel-Lock: sha1:qg8YwaUWgdrGQoGkaYrsJhK//pw=
Content-Language: de-DE
In-Reply-To: <20230106112959.738fadea@gargantua.manuelito.lan>
 by: Arno Welzel - Sat, 7 Jan 2023 15:05 UTC

Badarbo, 2023-01-06 11:29:

> Hello,
> with the code below, $rv is 0 :-)
>
> --- begin code ---
> $pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file','stderr.log','w']];
> $proc=proc_open('sleep 3',$pdesc,$pipes);
> fclose($pipes[0]);
> $rv=proc_close($proc);
> echo('rv: '.$rv.PHP_EOL);
> exit(0);
> --- end code ---
[...]

Do not trust the proc-Functions in PHP to get any process results. The
did not work reliable for this in PHP 7.4 and in 8.0/8.1 I never got any
useful result from proc_close().

If you really need to be sure to get the return code of the command you
called, wrap the call in a shell command and use the result from the
wrapper, like this:

<?php
$command = 'some-command-to-execute';

$descriptors = [
0 => ['pipe', 'r'], // stdin
1 => ['pipe', 'w'], // stdout
2 => ['pipe', 'w'], // stderr
3 => ['pipe', 'w'], // file descriptor for exit code
];
$process = proc_open($command.'; echo $? >&3', $descriptors, $pipes);
if (is_resource($process)) {
while ($output = fgets($pipes[1])) {
$shellOutput .= $output;
}
} if (!feof($pipes[3])) {
$shellResult = (int) rtrim(fgets($pipes[3], 5), "\n");
} fclose($pipes[3]);
proc_close($process);

// $shellOutput will contain the output of stdout
// $shellResult will not contain the return code

--
Arno Welzel
https://arnowelzel.de

Re: proc_open, proc_get_status, proc_close

<2087c440-bcf1-43cd-8a70-62befbf99834n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=879&group=comp.lang.php#879

  copy link   Newsgroups: comp.lang.php
X-Received: by 2002:a05:6214:b11:b0:621:357e:14de with SMTP id u17-20020a0562140b1100b00621357e14demr256867qvj.8.1685018459991;
Thu, 25 May 2023 05:40:59 -0700 (PDT)
X-Received: by 2002:a05:620a:191a:b0:75b:2a2e:62c9 with SMTP id
bj26-20020a05620a191a00b0075b2a2e62c9mr2653231qkb.2.1685018459826; Thu, 25
May 2023 05:40:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.php
Date: Thu, 25 May 2023 05:40:59 -0700 (PDT)
In-Reply-To: <20230106112959.738fadea@gargantua.manuelito.lan>
Injection-Info: google-groups.googlegroups.com; posting-host=85.253.157.80; posting-account=Z2IQwwoAAABGd-Hg2hj6qcUFc7sg_PhS
NNTP-Posting-Host: 85.253.157.80
References: <20230106112959.738fadea@gargantua.manuelito.lan>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2087c440-bcf1-43cd-8a70-62befbf99834n@googlegroups.com>
Subject: Re: proc_open, proc_get_status, proc_close
From: yefap33237@cutefier.com (V õ l u r)
Injection-Date: Thu, 25 May 2023 12:40:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2178
 by: V õ l u r - Thu, 25 May 2023 12:40 UTC

Go there

----->

https://groups.google.com/g/usa/c/HxOR8iWQQgA

And help me.

Badarbo kirjutas reede, 6. jaanuar 2023 kl 12:30:08 UTC+2:
> Hello,
> with the code below, $rv is 0 :-)
>
> --- begin code ---
> $pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file','stderr.log','w']];
> $proc=proc_open('sleep 3',$pdesc,$pipes);
> fclose($pipes[0]);
> $rv=proc_close($proc);
> echo('rv: '.$rv.PHP_EOL);
> exit(0);
> --- end code ---
>
> With the code below, $rv is -1 :-(
>
> --- begin code ---
> $pdesc=[0=>['pipe','r'],1=>['file','stdout.log','w'],2=>['file',stderr.log','w']];
> $proc=proc_open('sleep 3',$pdesc,$pipes);
> $done=false;
> while ($done===false) {
> $pstat=proc_get_status($proc);
> if (!$pstat['running']) $done=true;
> usleep(500000);
> }
> fclose($pipes[0]);
> $rv=proc_close($proc);
> echo('rv: '.$rv.PHP_EOL);
> exit(0);
> --- end code ---
>
> Why oh why?

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor