473,326 Members | 2,124 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,326 software developers and data experts.

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:\sandbox\bin\cprog.exe', $descriptorspec, $pipes);

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

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

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

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

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 1345

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

Similar topics

1
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...
0
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...
0
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...
4
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...
0
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...
4
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...
2
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...
5
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
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...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.