Say if STDOUT is redirected from Perl Script

So, I wrote a simple html 1.0 server, and I have some perl scripts on the server. In particular, I have this script, called my histogram, that is, an html form with a form action equal to another cgi file. Here is the code:

print "<form action=\"tallyandprint.cgi\" method=\"GET\">"; 

Now, when I call tallyandprint.cgi, it displays the graph using gnuplot and sends it to the user's browser (STDOUT is redirected to the html server code, so perl removes it). Now I also want to run tallyandprint.cgi from bash, but take a different style of arguments. Right now I am using Perl analysis to capture patterns by parsing the URL and separating the content between the + character (example :? Pattern = 1 + 2 + 3 + 4 is what the URL is).

Thats fine and dandy, but I do not want my arguments to be written in bash as 1 + 2 + 3 + 4, but rather separated in different ways. I tried using the Perl version of isatty (), but since the input is always from the terminal (because the server is executing it), I cannot distinguish whether the input is from bash or from a web browser in this way.

My next one, though, was to find out if STDOUT is being redirected. Because if the web server starts cgi, STDOUT will be redirected to the socket the user is connected to. If it is running in bash, STDOUT should be a regular tty. How can I check this in perl?

Thanks for the advanced.

+4
source share
1 answer
 if (-t STDOUT) { say "STDOUT is probably not redirected"; } else { say "STDOUT is probably redirected"; } 
+8
source

Source: https://habr.com/ru/post/1411015/


All Articles