By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

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

P: 2
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
Share this Question
Share on Google+
2 Replies

P: 2
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:\....\"

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

Expert 5K+
P: 5,821
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.