473,598 Members | 3,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

proc_open on windows: can't get stdin to a perl script

2 New Member
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.

Any advice? Could it be some sort of permissions thing?

Here is the PHP:

[PHP]
$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'r')
);

$pipes = array();
$resource = proc_open($comm and, $descriptorspec , $pipes);

if (!is_resource($ resource)) {
$fail = "Unable to launch process";

} else {
$stdin = $pipes[0];
$stdout = $pipes[1];
$stderr = $pipes[2];

fwrite($stdin, "this\nis\na\nt est\n");
fclose($stdin);

while (!feof($stdout) ) {
$ouput .= fgets($stdout);
}

while (!feof($stderr) ) {
$error .= fgets($stderr);
}

fclose($stdout) ;
fclose($stderr) ;

$exit_code = proc_close($res ource)
[/PHP]

And here is the simple perl script:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $output;
  7. while (<STDIN>) {
  8.     $output = "FOO: $_\n";
  9. }
  10.  
  11. print STDOUT "Test\n";
  12. print STDOUT $output;
  13.  
  14. exit 0;

All I see from the perl script in $stdout is"Test"....

Grateful for any help!
Aug 9 '07 #1
2 4031
kimonp
2 New Member
I found a way to make it work...perhaps somebody could comment on why this makes a difference:

If I change the command I am running to call perl directly:

"perl c:\....\foo.pl"

This works! Whereas:

"c:\....\foo.pl "

Did not work. Keep in mind though, it DID run it as via perl, just did not pass it the STDIN I was sending it from PHP.

Any ideas why this makes a difference?
Aug 9 '07 #2
pbmods
5,821 Recognized Expert Expert
Heya, kimonp. Welcome to TSDN!

The '.pl' extension is not enough to designate a perl script. On a *n?x system, you must also specify the interpreter using what is known as a shebang ('#!'). For example:
Expand|Select|Wrap|Line Numbers
  1. #!/path/to/perl
  2.  
I have no idea how Windows handles it, but I would imagine that explicitly calling the perl executable to interpret the file (as you have done) would be the way to go.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
5837
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
2284
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
3146
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
1664
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...
2
3189
by: razorfold | last post by:
Hi, I've written something that takes text and passes it to gpg to encrypt. It works great except when the text size is greater than 64k at which point PHP/Apache hangs. Is there any way around this? Below is a code snippet (which may or may not help). Thanks, -r
4
4863
by: arorap | last post by:
I've mod_php installed with Apache 2.2. In one of my folders, I'm using the cgihandler as the PythonHandler as my target host runs python only as CGI. Here cgi.FieldStorage() doesn't seem to work. I can see the form data in sys.stdin but cgi.FieldStorage() returns an empty dictionary. Here's the code for the test script I am posting to - -- #!/usr/bin/python
4
3777
by: jane007 | last post by:
Hello everybody: I am having a problem. On Unix platform, there is a script that need user to input data from console, then when I call Unix perl script from Windows, these is an issue occurs, when I input data and enter "enter" so fast, the Windows console is freezed, I don't know why, does anybody know?Thank you very much. My code like follows:
0
1354
by: Daniel Klein | last post by:
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...
6
5467
by: xhe | last post by:
I am using ffmpeg to convert video, this is a sample script: $str='/home/transla1/bin/ffmpeg -i /home/transla1/public_html/ cybertube/web/uploads/video/31_AK000005.AVI -s 240x180 -b 100k -ar 22050 -y /home/transla1/public_html/cybertube/web/uploads/video/ generated/31_70_AK000005.AVI.flv '; //exec($str); runExternal($str,$code); echo $code ;
0
8392
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
8050
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
6718
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
5850
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
5438
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
3897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
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.