473,750 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

proc_open problem: \n translates to Windows-style line return \r\n

Without getting into a lot of unnecessary detail, I'm working on a project
to allow PHP to communicate with a proprietary database.

The IPC mechanism I'm using is 'proc_open'; there is a server-side component
(written in C) that 'listens' for PHP requests (via its stdin) and spits out
the appropriate response (via its stdout). Conversely, the PHP side uses
fwrite() to send to the component's stdin and fread() to read from the
component's stdout.

Ok so far?

What happens is that there is a situation where the C component will send a
a string with an embedded chr(10) via stdout to PHP's stdin. On Windows this
is getting converted to chr(13).chr(10) .

So the problem is that if I send a n byte string ( with an embedded chr(10)
) then fread() gets an n+1 byte string ( with the addition of the chr(13) ).

I've already tried using the 'binary_pipes' in the 'other_options' array.

I've also tried adding a 'b' as a 'pipe' option (see code below) but PHP
doesn't like it.

Here's simplified PHP code to illustrate the problem :

$descriptorspec = array(
0 =array("pipe", "r"),
1 =array("pipe", "w"), //tried doing "wb"
2 =array("pipe", "r"));

$process = proc_open('C:\s andbox\bin\cpro g.exe', $descriptorspec , $pipes);

if (is_resource($p rocess)) {
$rtnval = fread($pipes[1], 1024);

echo "$rtnval <br />"
echo strlen($rtnval) ."<br /><br />";

$a = str_split($rtnv al);
foreach ($a as $character) {
echo ord($character) ."<br />";
}

fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($pro cess);
}

If the C program sends the string 'LINE1'.chr(10) .'LINE2' then PHP responds
with:

LINE1 LINE2
12

76
73
78
69
49
13 <---this is being added in by PHP
10
76
73
78
69
50
Is there some 'switch' that I can use to turn this off? Or am I going to
have to filter this out myself?

Daniel Klein
Feb 11 '08 #1
0 1358

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...
0
5852
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child
0
2292
by: Christian Hammers | last post by:
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. ...
4
3152
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
1668
by: Muffinman | last post by:
Howdy, For a script I need the exact output of the apache htdbm.exe to a var so I can extract all users from a database. Now I found out that this can be done with Proc_open. I got this script from the php website which looks something like copied below... Since I can not find very good documentation on this function my question is: I suppose that the problem is with this 2 => array("file", "error-output.txt", "w") // stderr is a file...
4
4562
by: darrin.skinner | last post by:
Hi all, How can I open a file/pipe to something other than STDOUT/STDERR? I.e. I want to write to file descriptor # 3. fopen("php://std3"... does not work. fopen("/dev/ttyS3"... does not work. Any ideas? For more detail on what I'm trying to do, its' something like this... -------------------------------------
2
4038
by: kimonp | last post by:
I am running on windows XP with a fresh install of wamp5 (1.7.2) and mediawiki. I am trying to call a perl function from within php using proc_open. The perl script is being executed and returns a successful exit value, and I can read the results it prints to STDOUT in PHP, but the perl script does not see STDIN from PHP. Since I want to use the perl script as a filter and I don't want to create an intermediary file, this is problematic....
5
3104
by: sakismat | last post by:
please help how can I get stderr from processes ($proc) in my screen without waiting the other processes to end #!/usr/bin/php <?php $con = mysql_connect("localhost", "user"); if (!$con)
0
1886
by: arkascha | last post by:
Helloooo everyone, I have a problem with a small solution I made some three or four years ago. Worked flawless until deployed onto newer machines now and guess what, I cannot fix it. Maybe some guru here can give this a look and tell a stupid newbie like me what I miss... The strategy is to have some kind of a shell-like wrapper and work interactively with it from my php scripts. So I setup a wrapper object and can write a command and...
0
1518
by: limweizhong | last post by:
I don't know why the following script intermittently crashes when I remove the sleep() call. I believe the pipes were not properly set yet before the shell statement was called, which used pipes also. This is on Windows 98 (I know it's a bit old), with PHP 5.2.5, and tlist and findstr came from the resource toolkit (ftp://ftp.microsoft.com/services/technet/samples/ps/win98/reskit). BTW I am trying to get the real PID of the process which was...
0
9000
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
8838
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
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
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
8260
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
6804
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...
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.