Perl help needed!

gopunk

Lifer
Jul 7, 2001
29,239
2
0
this script was working fine until today, but all of the sudden, it doesn't work anymore :(

basically i have a command that outputs a bunch of lines, and i want the perl script to grab this output and display it to the browser window (with some work done on the strings in between). so i have:

open(BLAH, "/directories/command arguments |") || die "can't fork: $!";
while($temp = <BLAH>){

print $temp;

}



do you guys see anything wrong?

thanks!
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
Originally posted by: Tyler
That should work, you sure it's not "/directories/command arguments" that's broken?

pretty sure... if i copy and paste the "/directories/command arguments" part (without the | pipe), and run it from the command line, it works like a charm.

uuugh. makes no sense...

oh and for what it's worth, it never enters the while loop


i'm not very knowledgeable about these things, when i run the command, is there more than one way for it to get output to the screen? like stdout or stderr or something.... maybe the pipe command doesn't grab whatever the command is really outputing because it's not looking in the right place?

i should also add that the way it doesn't work is that it doesn't output what the command outputs to the screen when run from the command line. it doesn't give any error or anything (that i can see)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: gopunk
Originally posted by: Tyler
That should work, you sure it's not "/directories/command arguments" that's broken?

pretty sure... if i copy and paste the "/directories/command arguments" part (without the | pipe), and run it from the command line, it works like a charm.

uuugh. makes no sense...

oh and for what it's worth, it never enters the while loop


i'm not very knowledgeable about these things, when i run the command, is there more than one way for it to get output to the screen? like stdout or stderr or something.... maybe the pipe command doesn't grab whatever the command is really outputing because it's not looking in the right place?

i should also add that the way it doesn't work is that it doesn't output what the command outputs to the screen when run from the command line. it doesn't give any error or anything (that i can see)

sounds like $temp = <BLAH> is evaluating as false, and therefore you're skipping your while loop. Is the first line of <BLAH> blank?
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Originally posted by: Tyler
In that case: while(<BLAH>){print}

or even slightly shorter:

print while <BLAH>;

:)

Did I just participate in a nerd programmer fight? :p I think you gave me a black eye!

 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
sounds like $temp = <BLAH> is evaluating as false, and therefore you're skipping your while loop. Is the first line of <BLAH> blank?

yea i think you're right about it being false... but i don't think it is because the line is blank (i thought it returned false only upon EOF). also, i have tried testing this with a file that has blank lines in front and it worked fine for that.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
try to see the contents of <BLAH> by:
printf <BLAH>;
(even shorter than "print while <BLAH>" :p)

also, try to print some debugging gibberish on the line before and after while() to see if the program continues running after the open()

other than that ... try removing the pipe "|" from the open() directives and see if it does any good?
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
hmmmm in the latest twist to our saga, it appears that the cgi script works fine from the command line, but has trouble printing to the webpage.

what makes this really weird is that not everything is missing... just the stuff that is supposed to get printed from the while loop. yet this shows up when run from the commandline.

WTF? :p
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
Originally posted by: Tyler
Does the webserver have execute permissions for the command you're running?

the command is rwxr-xr-x, so it shouldn't be an issue right? what's weirder yet is that if i declare a string and keep on concatenating the output of the file to it, and then print the string at the very end, it STILL doesn't work! do you think it could be something in the string itself, like the @ symbol in email addresses? but if it was that, how come it works for the command line....

also, here is something else... i declare the temporary variable before the while loop. in the while loop, i append the command output as well as "lalala", and print "blah". then after the loop, i append "hi", and finally print the whole thing.

when i run this from the webpage, all i get is "hi", yet when i run it from the command line, i get everything i should, output, lalala's, blah's, and the hi.
 

Creedyou

Senior member
Dec 28, 2001
205
0
0
are u printing to the write output stream because I don't think u can print to STDOUT if you want it on a webpage