LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2015, 10:48 AM   #1
Linicks
LQ Newbie
 
Registered: Sep 2015
Location: Pompey
Distribution: Slackware
Posts: 5

Rep: Reputation: Disabled
perl - get print to print *now* in cgi script (hard to explain).


Hi Guys and Gals,

Been a Slack user for over 12 years, and this has me beat.

I have a web form that some fields drive a binary to produce results, and other fields just grep a file for results.

Now, one field when used can take a few seconds to process, so if I put a:

print "This can take a seconds...";

before the backticks line, it doesn't print UNTIL the backticks command has finished?

Yet, if the previous functions in my code are run and print, it does print first and then waits for the backticks command.

So, something like this pseudo code works:

if (match) { # true

grep file;

print $results;

}

if (match) {

print "Please wait, can take a few seconds";

$var=`command'

print $results;

}

Which then runs the output from the first match, and then prints the 'Please wait...' line as the backticks command processes.

But IF the first match is false, the 'Please wait...' line doesn't get printed until the backticks command is finished, so it all gets printed at the same time, and the user sits looking at a 'loading...' thing in their browser.

Hope you understand what I mean, and thanks for any help why this happens/what is going on.

Nick

Last edited by Linicks; 12-13-2015 at 10:57 AM.
 
Old 12-13-2015, 01:08 PM   #2
Aia
Member
 
Registered: Jun 2006
Posts: 66

Rep: Reputation: 21
pseudo code

Code:
display "Please wait, it can take a few seconds"
if true
   execute command
   display result of command
else
   display result of failure
 
Old 12-13-2015, 02:06 PM   #3
Linicks
LQ Newbie
 
Registered: Sep 2015
Location: Pompey
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: Disabled
Already tried that, and various variations of it. None work, but some do.

It's like something just ignores it depending on what matches before it.

Why (as a standalone):

if (match) {

print "Please wait..."

$var=`command`;

print $var;

}

Doesn't output the first 'print' straight away, I don't know.

Nick
 
Old 12-13-2015, 03:02 PM   #4
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
A linefeed should flush the output buffer.
Code:
print "Please wait...\n"
If you can't live with that you need to turn on autoflushing (link).
 
Old 12-14-2015, 10:54 AM   #5
Linicks
LQ Newbie
 
Registered: Sep 2015
Location: Pompey
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you! This works great:

#!/usr/bin/perl -w $|++;

Nick
 
Old 12-14-2015, 12:15 PM   #6
Linicks
LQ Newbie
 
Registered: Sep 2015
Location: Pompey
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: Disabled
Actually, this isn't solved - sometimes it works, sometimes it doesn't and everything gets printed at once after a delay.

I am wondering if it is the browser doing something funny and just waits.

Nick
 
Old 12-24-2015, 08:14 AM   #7
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
The webserver may buffer as well... it probably does, so you have to tell your webserver not to buffer.

Searched on the interwebs for this issue on Apache HTTPD server with php... and this was one solution:
Code:
SetEnvIfNoCase Request_URI \.cgi$ no-gzip dont-vary
you may have to change .cgi to something else, like .pl or so...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Print output in a single line in perl script Venkadesh Linux - Newbie 4 01-28-2012 11:52 AM
perl script to print the message if the server is up or down after a certian time int Kames Linux - Newbie 1 07-22-2011 09:50 AM
Print output of a script to screen using Perl/Multiple installation of Perl Modules metallica1973 Linux - General 1 02-17-2011 05:59 PM
Trying to write a perl script that will print shell variable ohcarol Programming 2 04-16-2007 08:02 AM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration