ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have this old assembly program (nasm64) that does a good job of comparing strings in a particular way outside of CGI and I am trying to make it work as a CGI. It works correctly from the CLI but prints the typical square black boxes and question marks as a CGI (through a HTML/browser-document and Apache2), this string of garbage is always proportional to the length of the strings tested, so it is trying to print the string. In my test, ASCII strings are used but the program is intended to be used for true (non-ascii) utf-8 strings.
The same code in BASIC works perfectly (ascii tested again although the result should be the same with UTF-8 on a byte-by-byte comparison basis) but can't get the length given by CGI variable of the returned strings (how many bytes to read) and is too slow at string comparisons.
I have insufficient experience in C, Perl, PHP or Python etc and only a basic knowledge of Apache2 and this strings comparison is a real bottleneck in need of assembly code that I find is my fastest way of solving that sort of problems.
My questions are: What should I be looking for to solve the problem? Is Apache2 mis-configured/not-configured? I thought it was configured for UTF-8 by default and should automatically print through system call 1 (write) anything printable. Or could it be a GDM3 problem? Or a combination of both? Or do I miss something?
I assume the same code in C would give the same result so a solution for C would probably solve the problem in Assembly code.
Thank you for your help.
Unmodified Debian 7 and Apache2 from DVD installation.
New Gigabyte mobo AB350 with Feb 2017 BIOS.
where ... represents the output of the CGI and whatever HTML formatting might be also required...although only the meta tag is required to address your question. Please let us know how that works for you.
And to repeat NevemTeve's question...may we see the code and the output, please?
Thank you for the answers. My apologies, I was wrongly convinced it was so simple I did not think code was necessary, I also have to do this from the local library.
That's an excellent point!! I hadn't considered it because my CGI scripts are always plain text (perl) files, so when that happens to me it's very obvious.
rblampain, please show us how you are calling your program from the web page.
Edit: I just remembered why that happens. (tho I just saw that this is in the link Guttorm posted) The setting
Code:
AddHandler cgi-script .cgi .pl
in httpd.conf needs to include the suffix of the file to be executed, so if its .asm - add that to the AddHandler directive. Otherwise, apache doesn't know to execute the code, and just delivers it instead.
That is probably the problem. But I wouldn't add .asm to CGI programs, just assemble it to a binary ending in .cgi.
Good point. The OP probably already has a binary; it just needs to be renamed as something.cgi.
Sorry, I get caught up in the "root cause" and forget the simple solutions -- making the solution fit the conditions instead of 'tother way 'round...I also forget that some people might not have access to the httpd.conf
This is incorrect. If you send "Content-Type: text/plain" in the header, any browser will just display it as plain text. You do not have to send HTML.
Yes, that's true. Point is that the first thing from the script needs to be a "Content-Type:..." header followed by a blank line. If that's not present, the browser will report an error 500:
Code:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
malformed header from script. Bad header=<html>: popup.pl
If you think this is a server error, please contact the webmaster.
Error 500
(this example is a script without the header so the first thing it sends is the <html> tag)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.