• proc_open, proc_get_status, proc_close

    From Badarbo@21:1/5 to All on Fri Jan 6 11:29:59 2023
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=c3=b8j?=@21:1/5 to Badarbo on Fri Jan 6 09:07:46 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to Badarbo on Fri Jan 6 17:35:08 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Sat Jan 7 16:05:44 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ezimene nimi Teine nimi@21:1/5 to Badarbo on Mon Mar 6 03:25:44 2023
    Get to: http://aaaaaaaaaaaaaaaar.medianewsonline.com/firstpage.php

    And invite all Your friends too !!!!!!!!!!!




    On Friday, January 6, 2023 at 12:30:08 PM UTC+2, Badarbo wrote:
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to Ezimene nimi Teine nimi on Mon Mar 6 16:22:46 2023
    Ezimene nimi Teine nimi <techfan55555@hotmail.com> wrote:
    : Get to: http://aaaaaaaaaaaaaaaar.medianewsonline.com/firstpage.php

    : And invite all Your friends too !!!!!!!!!!!




    : On Friday, January 6, 2023 at 12:30:08=E2=80=AFPM UTC+2, Badarbo wrote:
    : > Hello,=20
    : > with the code below, $rv is 0 :-)=20
    : >=20
    : > --- begin code ---=20
    : > $pdesc=3D[0=3D>['pipe','r'],1=3D>['file','stdout.log','w'],2=3D>['file','= : stderr.log','w']];=20
    : > $proc=3Dproc_open('sleep 3',$pdesc,$pipes);=20
    : > fclose($pipes[0]);=20
    : > $rv=3Dproc_close($proc);=20
    : > echo('rv: '.$rv.PHP_EOL);=20
    : > exit(0);=20
    : > --- end code ---=20
    : >=20
    : > With the code below, $rv is -1 :-(=20
    : >=20
    : > --- begin code ---=20
    : > $pdesc=3D[0=3D>['pipe','r'],1=3D>['file','stdout.log','w'],2=3D>['file',s= : tderr.log','w']];=20
    : > $proc=3Dproc_open('sleep 3',$pdesc,$pipes);=20
    : > $done=3Dfalse;=20
    : > while ($done=3D=3D=3Dfalse) {=20
    : > $pstat=3Dproc_get_status($proc);=20
    : > if (!$pstat['running']) $done=3Dtrue;=20
    : > usleep(500000);=20
    : > }=20
    : > fclose($pipes[0]);=20
    : > $rv=3Dproc_close($proc);=20
    : > echo('rv: '.$rv.PHP_EOL);=20
    : > exit(0);=20
    : > --- end code ---=20
    : >=20
    : > Why oh why?

    This abusive spamtroll came from

    X-Received: by 2002:ac8:4146:0:b0:3bf:ff6d:ad8b with SMTP id e6-20020ac84146000 000b003bfff6dad8bmr2996144qtm.9.1678101944897;
    Mon, 06 Mar 2023 03:25:44 -0800 (PST)
    X-Received: by 2002:a81:b61a:0:b0:52e:c79a:cda with SMTP id
    u26-20020a81b61a000000b0052ec79a0cdamr6571078ywh.10.1678101944674; Mon, 06
    Mar 2023 03:25:44 -0800 (PST)
    Path: news.nk.ca!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.c
    om!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!new
    s.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!g
    oogle-groups.googlegroups.com!not-for-mail
    Newsgroups: comp.lang.php
    Date: Mon, 6 Mar 2023 03:25:44 -0800 (PST)
    In-Reply-To: <20230106112959.738fadea@gargantua.manuelito.lan>
    Injection-Info: google-groups.googlegroups.com; posting-host=82.131.38.37; post
    ing-account=ogslnwoAAACd9vU9PADzlWBA81fSuNpL
    NNTP-Posting-Host: 82.131.38.37
    References: <20230106112959.738fadea@gargantua.manuelito.lan>
    User-Agent: G2/1.0
    MIME-Version: 1.0
    Message-ID: <63b8ae86-884d-4cce-b13f-e3e682f7c328n@googlegroups.com>
    Subject: Re: proc_open, proc_get_status, proc_close
    From: Ezimene nimi Teine nimi <techfan55555@hotmail.com>
    Injection-Date: Mon, 06 Mar 2023 11:25:44 +0000
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: quoted-printable
    X-Received-Bytes: 2271
    Xref: news.nk.ca comp.lang.php:167964


    Spamtrollers are trolls posting useless spam thinking it is content
    but are posting useless noise. Spamtrolls are newsgroup vandals!
    Thoses trolls are as bad as Donald
    Trump on Twitter.

    This makes https://groups.google.com/search/conversations?q=Depeer%20Google%20Groups

    Depeer Google groups Now!!
    --
    Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
    Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising! Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b We cannot defy gravity without paying a price. -unknown Beware https://mindspring.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?V_=C3=B5_l_u_r?=@21:1/5 to All on Thu May 25 05:40:59 2023
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)