473,372 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

terminal locks up upon second running of this CLI PHP function

[PHP]
function &getResponse() {

/*----------------------------------------------------------------------------------------------
New 7/29/2005: Windows can use STDIN, however, the 'con' input data
stream, i.e. 'console',
is built into DOS functionality and produces a better data input
stream result. Use that
for Windows. If this stream is not available or if you are using
UNIX, you will simply
open using STDIN by default
-----------------------------------------------------------------------------------------------*/
if ($_ENV['windir'] || $_SERVER['windir']) $responseID =
@fopen('con', 'rb');
echo "111test111\n";
if (!$responseID) $responseID = @fopen('php://stdin', 'r') or
die('Cannot read stdin: ' . STDERR);
echo "\nresponseID = $responseID 222test222\n";
while (($response = @fgets($responseID, 1024)) !== false) {
echo "333test333\n";
@fclose($responseID);
return $response;
}
}
[/PHP]

This is what you get upon running:


php -q /home/phillip/docs/mu-spin/image_catalog/install.php
Is this your first time creating the tables into the database "ivc"?
(y/n Enter = n)111test111

responseID = Resource id #22 222test222

333test333

1where am I?
Do you want to repopulate the usernames table (y/n Enter = n)111test111

responseID = Resource id #25 222test222

[Just sits there until you hit CTRL-C and break out]
Environment: PHP 5.0.4 using Fedora Core 4

The purpose of getResponse() is simply to wait for user response from
STDIN and return whatever the user sends back.

Thanx
Phil

Aug 12 '05 #1
2 1352
Tried to perfect it, to no avail. Still locks up cold when you're
trying to input using PHP 4.3.8 - PHP 5.0.4 using Fedora Core 4.

[PHP]
function &getResponse() {

/*----------------------------------------------------------------------------------------------
New 8/12/2005: If constant STDIN exists, a constant data-input stream
exists and there is no
need to open an input stream. Retrieve from there and return. Only
available in PHP 4.3+
to PHP 5+ and if STDIN consists of a valid constant input stream
-----------------------------------------------------------------------------------------------*/
$version = trim(substr(exec('php -v'), 3, 8));
if ((preg_match('/^4\.[3-9]/', $version) || preg_match('/^5\.[0-9]/',
$version)) && STDIN) {
$response = trim(@fgets(STDIN, 256));
return $response;
}
/*----------------------------------------------------------------------------------------------
New 7/29/2005: Windows can use STDIN, however, the 'con' input data
stream, i.e. 'console',
is built into DOS functionality and produces a better data input
stream result. Use that
for Windows. If this stream is not available or if you are using
UNIX, you will simply
open using STDIN by default
-----------------------------------------------------------------------------------------------*/
if ($_ENV['windir'] || $_SERVER['windir']) $responseID = @fopen('con',
'rb');
if (!$responseID) $responseID = @fopen('php://stdin', 'r') or
die('Cannot read stdin: ' . STDERR);
if ($responseID) {
while (($response = @fgets($responseID, 1024)) !== false) {
@fclose($responseID);
return $response;
}
return "\n"; // DEFAULT SINCE NOTHING COULD BE OBTAINED
}
return "\n"; // DEFAULT SINCE NOTHING COULD BE OBTAINED
}
[/PHP]

Phil

Aug 12 '05 #2
GOT IT! Apparently there is a "feature" in older PHP versions than
4.3.3 that can't interpret STDIN, whereas certain newer versions of PHP
(4.3.11 - 5.0+) can't interpret (php://stdin) either!

Phil

Aug 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sara_S | last post by:
I am ready to move my ASP web site onto a remote host. The problem is that when I use Terminal Services to see the host machine, the error does not show up. (I was told that debugging info is only...
1
by: aswinee | last post by:
I am running Microsoft SQL Server 2000 - 8.00.760 Enterprise Edition on Windows 2003 Enterprise Edition (NT 5.2 Build 3790:) I have 4CPU and 8GB of RAM. I have AWE enabled, /pae /3gb switch is on...
3
by: ACP | last post by:
Hi all, Have a situation that my company has never run across before. Client is running NT4 for the domain server, using terminal services 2000 and running an application with a SQL Server...
14
by: mystilleef | last post by:
Hello, A user of my application points me to a behavior in gVim, the text editor, that I would like to implement in my application. When gVim is launched from a shell terminal, it completely...
11
by: EoRaptor | last post by:
I`m exporting data from many Lotus Notes databases to a DB2 database using LotusScript. The LotusScript agents commit after EACH update/insert. Nevertheless, I keep getting transaction rollbacks on...
28
by: (Pete Cresswell) | last post by:
I'd like to dabble in Terminal Server enough to see if I can get some of my MS Access apps to run through it. I've got the MSDN subscription. Is there enough there for a real-world...
4
by: Jon Davis | last post by:
I have a Windows Forms application where I normally had two threads running, with the second thread started by a main window. The second thread ran in the background just fine. Then I made some...
10
by: gary0gilbert | last post by:
An unusual spin to this recurring disk or network error in a Terminal Server environment. Access 2000, Terminal Server 2000, file server is windows 2000. All users have a separate copy of the...
16
by: =?Utf-8?B?RHdlZWJlcmVsbGE=?= | last post by:
I created an Access 2007 application for my customer. The application is shared by three employees on a server. It maintains a contact list including financial data and social security numbers. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.