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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI executables in QBasic 1

Status
Not open for further replies.

Javin

Programmer
Aug 4, 2000
10
0
0
US
Visit site
I've used QBasic for years, but still know just enough to be dangerous.&nbsp;&nbsp;Can I get any suggestions for writing CGI in QBasic?<br><br>I tried this to test:<br><br>PRINT &quot;Content-Type: text/html&quot;<br>PRINT<br>PRINT &quot;&lt;HEAD&gt;&lt;TITLE&gt;This is a test.&lt;/TITLE&gt;&lt;/HEAD&gt;&quot;<br>PRINT &quot;&lt;BODY&gt;&quot;<br>PRINT &quot;&lt;/BODY&gt;&quot;<br><br>I'd assumed that when called it would spit out a simple web page.&nbsp;&nbsp;Instead, it glitches out, and won't run on the server, so I obviously have the wrong idea of how CGIs work.&nbsp;&nbsp;Could someone give me a hand here?<br><br>By-the-way, I've tried getting into that <A HREF=" TARGET="_new"> site, and it doesn't work.<br><br>-Javin
 
A CGI script is usually written in Perl, not Qbasic.&nbsp;&nbsp;A browser doesn't understand *.BAS files.&nbsp;&nbsp;If you want, you can find a Perl/CGI tutorial at <A HREF=" TARGET="_new"> a very powerful language.<br><br>And on the qb45.com thing, click on Qbasic/QuickBasic at the top.
 
CGI scripts are often used to present form-based pages, such as <b>order forms or surveys</b> not just simple text contents. <p> <br><a href=mailto: > </a><br><a href= > </a><br>Secrete of life: If Husband = Happy then Wife = Unhappy. If Wife = Happy then Husband = Unhappy. If Parents = Happy then Kids = Unhappy. If Kids = Happy then Parents = Unhappy.
 
the code should work fine (remove the second PRINT statement, or use 'PRINT &quot;&lt;br&gt;&quot;')<br><br>You gotta compile to .EXE in order to make it work or maybe it won't work ? dunno, never try it before.<br><br>Use QuickBASIC or some other BASIC compiler to compile it.<br><br>
 
See, that's just it.&nbsp;&nbsp;I have another .EXE file that does the EXACT same thing, gives you the exact same output when run, and it works.&nbsp;&nbsp;So I wrote the QBasic program to mimic it, and compiled it into an .EXE, yet the server kicks an error when it's run.&nbsp;&nbsp;<br><br>Is there maybe a different method that the information is actually being put out?&nbsp;&nbsp;I'm going to be dealing with sensitive information, so I don't want to use a perl or VB script.&nbsp;&nbsp;I need to have something that's going to be fairly safe.&nbsp;&nbsp;Any scripts can be downloaded from the server, picked apart, and then they'll know the structure of the data on your server.<br><br>-Javin<br><br><br>
 
I think it's probally need to be a specific type of exe. for example if I am correct in Qbasic you are mimicing to the console, where to a CGI you arnt directly communicating with a USer, more rather I belive you grab the input from the user then process it, but QBasic may be expecting a Dos Console. Not a Server. Some Languages just might not be adapt to be used in CGI. <p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Yeah, that's precisely what I'm afraid of.&nbsp;&nbsp;I know it can be done, because I've SEEN people make CGI EXEs in QBasic, but I've never seen the code.&nbsp;&nbsp;I'm afraid it's going to turn out to be some massively complex method of outputting the data by writing it out to a specific port or something.<br><br>-Javin
 
that or they had some special library made for QB45, to allow you to create the exe more easily, for example, until someone made that Graphical lib in ASM(Assembly) Qbasic graphics always been extremely slow. <p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
kb244 is right. QB writes to the CON device during a print routine, that's why it can't form flat binaries. CGI's in perl and C always write to STDOUT, which the web server can read. QB can probably do it, but it'll probably be easier to learn perl. You'll find that perl's structure is very close to BASIC, since they are both interpreted.
 
Excellent link, eliuker! I know a few guys who have been banging their heads trying to find a way to do this. I'll pass it on.
[sig]<p> <br><a href=mailto: > </a><br><a href= plain black box</a><br><i>"I sure hope I'm retired when it comes time to fix all the the Year-2000 problems in our systems!"</i><br>
<b>Edward Yourdon, <u>Time Bomb 2000</u></b>[/sig]
 
Eliuker-

You are a GOD. That's exactly what I was looking for! Thanks a bunch!

-Javin [sig]<p>Javin<br><a href=mailto:Javin@Javin-Inc.com>Javin@Javin-Inc.com</a><br><a href= Inc.</a><br><br>
Why don't sheep shrink when it rains?[/sig]
 
Okay, new problem. I thorougly read through (even printed out) the link you gave me. Unfortunately, it's talking specifically about DOS CGI. DOS CGI isn't supported by my host, (nor is Perl, for some bizarre reason) so that's still a no-go. Here's what I'm trying to do:

DEFINT A-Z

InStr$ = ENVIRON$(&quot;QUERY_STRING&quot;)

PRINT &quot;Content-Type: text/html&quot;
PRINT &quot;&quot;
PRINT &quot;<HEAD><TITLE>This is a test.&quot;
PRINT &quot;</TITLE></HEAD>&quot;
PRINT &quot;<BODY>&quot;
PRINT &quot;This is a test.&quot;
PRINT &quot;Your input was as follows:&quot;
PRINT InStr$
PRINT &quot;</BODY>&quot;

Still, even when given the proper permissions, it doesn't work.

-Javin



[sig]<p>Javin<br><a href=mailto:Javin@Javin-Inc.com>Javin@Javin-Inc.com</a><br><a href= Inc.</a><br><br>
Why don't sheep shrink when it rains?[/sig]
 
hmmmm as i say if your server dont got it make your own!
has a server that will run on win95/98
did I also mention its VERY easy to use.

Have a nice day.
 
Ahh Javin I see why your program still dosent work.
although your program can get info from the server the server cant getinfo you send to it because you must send the print statements to the output_file. try this code (I havent yet).

<-------Start Copying here------->
DEFINT A-Z

InStr$ = ENVIRON$(&quot;QUERY_STRING&quot;)
outfile$ = ENVIRON$(&quot;OUTPUT_FILE&quot;)

open outfile$ for output as #1
PRINT #1,&quot;Content-Type: text/html&quot;
PRINT #1,&quot;&quot;
PRINT #1,&quot;<HEAD><TITLE>This is a test.&quot;
PRINT #1,&quot;</TITLE></HEAD>&quot;
PRINT #1,&quot;<BODY>&quot;
PRINT #1,&quot;This is a test.&quot;
PRINT #1,&quot;Your input was as follows:&quot;
PRINT #1,InStr$
PRINT #1,&quot;</BODY>&quot;
close #1
<-------End code------->

You were just printing but as the docs say you have to print to the output_file other wise its pretty pointless huh?
 
Javin,
I'm just getting started in this cgi-bin thing and have alot of QuickBasic 4.5 background. This thread set was interesting and I'm wondering if you now have it down pat.
Can a compiled QB .exe file be used successfully as CGI? If so, what are the basic "need-to-knows"?
thanks
 
1) did you follow a link?
Get thing about "DOS-CGI" part (server must support it)
2) output in binary form, so you can output generated JPG/GIF. If QBAsic can't do that - you'll end up with text output only
3) last thing. This is not exact quote; I cannot recall the author just now, but it can make you wonder.

"I played with CGI in VB for a month... then I get into Perl and easily recreated in 3 days all I got in VB in a month".
 
Yes, you need a server that supports "DOS CGI" which is a sort of a kludge like the old "Win CGI" that was used to support VB 3 for writing CGIs.

I've written lots of CGIs in VB 6. These work fine with more generic servers like IIS or SimpleServer: There are some hoops to jump through there too, but they aren't as insurmountable as writing a true QB CGI seems to be. To expedite this I wrote a VB 6 program that takes very ASP-like syntax and generates and compiles a VB 6 CGI EXE.

That doesn't help here though. Sorry Javin.
 
I found the problem and developed a hack around it (actually just an implementation of Microsoft's fix for the trouble).

I posted it over at QBasic/QuickBasic News in the forums (see Programming Help: Projects there). I figured there were more QB developers on that site who might steal some of the ideas and benefit from them.

The actual problem: Windows has a problem with StdIO redirection to a 16-bit console application, described as a "hung pipe."

The (or one) fix: a 32-bit console application "stub" that fires up the 16-bit QB EXE in the same console after redirecting the new process' StdIO streams to its own. There are stubs for this sort of thing around written in C and Delphi. I did one in VB6.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top