php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24123 proc_open Apache 1.3.27 with php 4.3.2
Submitted: 2003-06-11 08:43 UTC Modified: 2003-08-09 20:10 UTC
From: zambrow at hotmail dot com Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 4.3.2 OS: Windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zambrow at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-06-11 08:43 UTC] zambrow at hotmail dot com
Apache 1.3.27 with php 4.3.2.   I'm tryin to implement a way to do a 2-way communication through telnet for my script
here's what I've found! (111.111.111.111 example ip is a unix box and it is accepting telnet connections"
Consider this.

$failed = false; // authentication failure flag
$cmd="telnet 111.111.111.111";
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$userID="user";
$password="password";
$process = proc_open("$cmd", $descriptorspec, $pipes);
echo $process;
if (is_resource($process)) {
    fwrite($pipes[0], "$userID\r");
    fwrite($pipes[0], "$password\r");
     fwrite($pipes[1], "exit\r");
    while(!feof($pipes[1])) {
        $line = fgets($pipes[1], 1024);
        $loginFailed = strpos($line, "invalid login name or password");
        if ($loginFailed != false)
        {	$failed = true;
        	// echo "FAILED LOGGING";
        }
        // DEBUG OUTPUT 
         echo $line;
         echo "---<br>";         
    } 
    fclose($pipes[1]);
    $return_value = proc_close($process);
    echo "<br><b>command returned<b> $return_value\n";
}
The following will result in empty pipes[1].  I'm unable to get anything out of that pipe as well the fgets just seems to hang.  when i try the same code on AIX platform it works.  So i'm thinking its a bug...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-11 08:55 UTC] wez@php.net
Your script is broken (why are you writing "exit" to $pipes[1]?).

Can you please indicate what you expect to see, and what you actually end up with?
Add this line after the proc_open call:
debug_zval_dump($pipes);

Also note that for telnet on most unix platforms, you need to run it via the "expect" utility to correctly emulate an interactive tty. (I know this is listed as a win32 issue, but its worth mentioning this in any case).





 [2003-06-11 13:56 UTC] zambrow at hotmail dot com
the fwrite($pipes[1], "exit\r");
was just my mistake i made during debugging but it doesnt change anything
I expect to see in pipes[1] the ouput of my telnet session. for example writing ls to pipes[0] should result in pipes[1] having the output of ls command in the running directory.
Adding your debugging function does not change anything.  The script will still just sit there for a long while and in the end it'll load empty page.
Note i'm doing this on Windows 2000 machine. and my target os is AIX.  if i run the script on AIX to AIX platform this seems to work
 [2003-08-09 20:10 UTC] pollita@php.net
I presume you're using the stock "telnet" application delivered with Win2000.  This program does not permit communicating via redirected pipes.  This is most directly illustrated by the following command:

C:\> telnet 111.111.111.111 > telnet.log

One would expect telnet to behave nicely and send the welcoming "login:" prompt to the telnet.log.  However, it simply bails because Windows Telnet doesn't like redirected pipes.

Thank Billy for that.

Unfortunately this isn't a bug in PHP and hence isn't something we can do anything to correct.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Apr 28 12:01:34 2025 UTC