Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blocking Echo Statements 2

Status
Not open for further replies.

iaresean

Programmer
Mar 24, 2003
570
ZA
Help!

I am writting a perl cgi script. I am basically converting a shell based program into a web based version. The problem is the files that the shell based program uses is filled with echo and print statements. These statements obviously clutter up and mess up my webpage when I run the file.

Is there a way to block any incoming echo statements, so that I can output my formatted webpage after the processing is complete.

Thanks for all your time and effort you put into helping me, a very inexperienced beginner.
 
@results=`myscript.???`;#using backticks will execute your
#script, and the array @results
# will store the output of the
# command
foreach $result (@results) {
print &quot;$result<br>\n&quot;;
}
As for blocking echo and print statements, these should no longer be required as you're going to be printing out your results in whatever format you like

HTH
--Paul
 
Thanks for the help PaulTEG, but let me clarify my issue a bit further:

I am running a shell based perl program that uses various files using the system(&quot;..&quot;) command. In fact alot of various files are used throughout the system by this program.

Now I am busy converting the program into a web paged version. I still want to use the original files however and just suppress their output commands that are contained within them (my problem) and then simply print out whatever I want after the processing is complete onto a blank webpage.

Here is a simple example of my code:

#!/usr/bin/sudo /usr/bin/perl

use CGI::Carp &quot;fatalsToBrowser&quot;;
use CGI ':standard';

require &quot;somefile.pl&quot;;

my $query = new CGI;

####---I CHECK TO SEE IF THE PAGE HAS CALLED ITSELF ALREADY (IF THE FORM HAS ALREADY BEEN PROCESSED?)---###

...CHECK IF SUBMITED

###---IF THE FORM WAS NOT PROCEESSED YET, I DISPLAY THE FORM BELOW, ALLOWING USER TO ENTER DETAILS---###

...DISPLAY FORM

###---ELSE IF THE FORM WAS PROCESSED (THERE ARE VALUES) I USE THE VALUES IN THE PROCEDURES LIKE BELOW (JUST AN EXAMPLE)--#####

$eg = procedure_p(); # This procedure comes from a file that was required at the top

system (&quot;/usr/bin/adduser $login $name&quot;);
system (&quot;/usr/bin/update $login&quot;);

###--The above three commands all contain echo statements, which I can't remove, because they must remain in tact for the shell based version that people run. But I do not want their output to be displayed on the webpage--####

####--Now I print what I want to the webpage--####

print &quot;WELL DONE, you have successfully added a user&quot;;
print &quot;<P> These two lines should only be displayed, nothing else!&quot;;


Now, I am looking for a method where a can suppress the echo statements for the duration of the commands being called, or a method to clear the screen after the commands have been called and then output whatever I want on screen.

Thanks again to anyone who puts time into helping me out.
A very inexperienced perl programmer.
 
if is the jobbie here

If you can edit the shell scripts, get them to accept a parameter. If the parameter is passed its the webversion else its the shell version, and in the scripts make the echo & print commands conditional on no additional parameter being passed.

Actually, if you're up for it you should rewrite the shell scripts to be called from another script that has the print commands, and then you'd be able to use the same core components (without the print statements) for the shell and web based versions

To fully suppress the echoes and prints, you could redefine STDERR, and STDOUT to dev/null - though if there's an issue you're not going to see it.

HTH
--Paul

 
Thanks once again PaulTEG for your quick responses, it is much appreciated.

Editing the scripts is definitely out of my options. The webpage has to call alot more scripts that what was shown in my example. And to make it worse those scripts call other scripts, and then even those scripts call other scripts. Editing them all would be too time consuming, and in some cases impossible, because some of the files are in binary format and I do not have the source.

So I just want to disable the output while I process exterior files, and then switch the output back on after the files have been processed.

Your idea with STDERR and STDOUT sounds pretty good, do you perhaps a small example I can take a look at, or a link perhaps?

Thanks once again, from a very inexperienced perl programmer.
 
How about calling each script in this way:
[tt]
system (&quot;/usr/bin/adduser $login $name >/dev/null 2>&1&quot;);
[/tt]
The [tt]>/dev/null][/tt] sends standard output to the &quot;bit bucket&quot; - i.e. it discards it. The [tt]2>&1[/tt] (if I remember my shell scripting correctly) sends standard error to the same place.

-- Chris Hunt
 
Thanks alot ChrisHunt, this worked like a charm and was exactly the type of thing I was looking for: code that is easy to implement.
 
Sean,

The issue still remains that if there's an error, or warning, you're not going to see it

--Paul
 
A good point PaulTeg, and this may become a very big issue. However the system I am converting has been in use for years and is to our knowledge without fault. The output I am blocking is merely friendly little messages explaining what is being done. I have also discovered another way of hiding this output so that it doesn't show on the web page, but if I look at the source it is visible. Using this method I could uncover any error messages, but I don't think any errors will occur.

A big thanks to PaulTeg and ChrisHunt for all your effort put into my problem.
 
Supressing error messages in the browser should be as simple as
Code:
print &quot;<&quot;;
system(&quot;/usr/bin/adduser $login $name&quot;);
print &quot;>&quot;;
Also
Code:
print &quot;<!--&quot;;
system(&quot;/usr/bin/adduser $login $name&quot;);
print &quot;-->&quot;;
Any thing inside the angle brackets should be taken by the browser as a HTML directive, though this may not work on less forgiving browsers.

The second will leave the code inside as a comment which is probably best

Regards
--Paul
 
Yep, another valuable piece of advice PaulTEG. I have changed over to the commented version. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top