471,863 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

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:

$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'r')

$pipes = array();
$resource = proc_open($command, $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\ntest\n");

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

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


$exit_code = proc_close($resource)

And here is the simple perl script:

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

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

Grateful for any help!
Aug 9 '07 #1
2 3829
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:


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
5,821 Expert 4TB
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
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

Post your reply

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

Similar topics

reply views Thread by Christian Hammers | last post: by
reply views Thread by Muffinman | last post: by
2 posts views Thread by razorfold | last post: by
4 posts views Thread by arorap | last post: by
reply views Thread by YellowAndGreen | last post: by

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.