473,767 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

proc_open and blocking fread / tri-directional pipes

Hello

I would like to call a unix shellscript from within a PHP script and
- write data to its STDIN
- read data from its STDOUT *and* STDERR
- get its exit code afterwards

proc_open seems to be the right thing to use but I have the problem that the called program gives >8kb data on both stdout/stderr back which causes my PHP script to simply hang in the fread call. To be precise the first 4096 "O" characters are read and displayed.

The problem is described in the first user comment to proc_open at www.php.net but the solution there writes stderr to a file (which never blocks) and therefore does not work for me.

Does anybody know a solution? stream_set_bloc king sounds good but
simply calling it with $pipes[1] and $pipes[2] as "stream" argument does not have the wished effect.

bye & TIA,

-christian-

My test program:

$pipe_spec = array(
0 => array("pipe", "r"), # stdin
1 => array("pipe", "w"), # stdout
2 => array("pipe", "w") # stderr
);
$process = proc_open("/tmp/testshellskript ", $pipe_spec, $pipes);

# stdin
if (fclose($pipes[0]) == 0) trigger_error(" fclose0", E_USER_ERROR);

# stdout
while ( ! feof($pipes[1])) print fread($pipes[1], 8192);
if (fclose($pipes[1]) == 0) trigger_error(" fclose1", E_USER_ERROR);

# stderr
if (fclose($pipes[2]) == 0) trigger_error(" fclose2", E_USER_ERROR);

And the called shell script (writes the chars each 7000 times):

#!/usr/bin/perl
print(STDOUT ("O"x7000)."\n" );
print(STDERR ("E"x7000)."\n" );
Jul 17 '05 #1
0 2293

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

Similar topics

1
2528
by: Alan Little | last post by:
I'm struggling with proc_open(). What I'm trying to do is conduct an sftp session. The process appears to open fine, but anything I send to it with fwrite() is ignored, and any output from sftp is simply dumped to my script's stdout, rather than being captured by fread(). Could someone give me a quick rundown of how to do something like this? The examples in the manual don't seem to work for me. This is on a FreeBSD system. -- Alan...
4
3154
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the drama) I've been trying to think of good ways to get Perl code to run inline in a PHP script. Here are a few of my ideas. If anyone has any further ideas, resources, or knows of someone else who's solved this already, please do tell... 1.) The...
0
2073
by: FrenKy | last post by:
Hi *. I get this error when trying to run proc_open() function: "Fatal error: Call to undefined function: proc_open() in /home/frantic/public_html/a/phpshell.pup on line 140" Does anybody knows what setting I have to change to fix this? Configuration:
0
1953
by: yawnmoth | last post by:
popen / proc_open seem to be broken (as per PHP Bug #30463). As such, does anyone know if there are any alternatives to them? I tried to use fsockopen to load a bunch of instances of a script to no avail (it doesn't seem to work within a for loop).
2
2899
by: razorfold | last post by:
Hi, I've been trying to run gpg through proc_open() and have failed all weekend. I keep getting this error from stderr: "/usr/bin/gpg: error while loading shared libraries: cannot restore segment prot after reloc: Permission denied" Im running php 4.3.11 on fedora 3. Here is the method i've been debugging. It should just run '/usr/bin/gpg --version' and display the
0
1557
by: yaront | last post by:
Hi, I'm using proc_open to start a process on a WindowsXP server. If the process that I start crashes for some reason, the whole PHP parsing hangs. When opening the TaskManager I can see my process still exists, meaning it actually hasn't ended although it crashed. any ideas how to solve this?
0
1118
by: Mitch Amiano | last post by:
Tri-XML 2005 is on for July 28-30th, in Raleigh, NC. The conference index is at <http://www.trixml.org/confindex.shtml>. Curious readers can get an idea of the conference from a review of Tri-XML 2004 at <http://home.agilemarkup.com/article8.2>. The Tri-XML Conference is a three-day conference in Research Triangle Park, NC. Begun by a user group, Tri-XML, the conference brings in national XML experts to present over 30 sessions. Tracks...
0
1175
by: Scott Abel | last post by:
Tri-XML 2005 -- Annual Conference, July 28-29, 2005 -- McKimmon Center (NC State University) Info: http://www.trixml.org/confindex.shtml Three days -- only $199 Come to Tri-XML 2005 and learn how others are using XML to create structured documentation, utilize the power of content management systems, and much more. Best practice sessions, case studies and hands-on workshops are all planned to help you learn from others an take that...
1
6358
by: Aaron Queenan | last post by:
Is there any way to have tri-state checkboxes in the TreeView, preferably without having to use the state icons for that purpose. Does anyone have or know of an implementation of tri-state checkboxes for the TreeView? Thanks, Aaron Queenan.
0
1145
by: Mitch Amiano | last post by:
I thought some of the list members might be interested (whether active or lurkers)... For the past few years, we've held the Tri-XML conference here in the Research Triangle Park area. This fourth year we again have an interesting roundup of leaders in the XML arena, speaking about workflow and other emerging XML technologies such as AJAX, ATOM, and DITA. The conference is pulled together each year by the XML user group I'm involved...
0
9571
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9405
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9841
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8838
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7383
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.