473,573 Members | 2,781 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 4030
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
5832
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
2273
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...
4
3145
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...
0
1662
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...
2
3184
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
4861
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 - ...
4
3774
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...
0
1353
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,...
6
5465
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...
0
7674
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...
0
7989
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. ...
0
8182
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...
1
7744
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...
1
5559
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...
0
5271
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...
0
3708
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...
0
3708
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1008
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...

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.