Solved

CGI with Dos batch?

Posted on 2002-06-21
7
338 Views
Last Modified: 2013-12-25
Just for fun:
Is it possible to create a CGI using a dos batch file?
If so, how does one issue the double \n\n ?

I tried the echo with character (255), but that's a value not a plain linefeed.







Please don't lock this question.
I will choose an answer from the comments.
0
Comment
Question by:Triskelion
  • 4
  • 2
7 Comments
 
LVL 15

Expert Comment

by:samri
ID: 7099980
Triskelion,

Basicall, any programming language/script/etc. could be used as CGI program if it can send-out the data as per CGI/HTTP protocol requires.

To be simple, the code should be able to at least send out

Content-Type: text/html\n\n  as the first line on the code.

I am having the same problem like you mentioned; How do we send out \n\n.  One possibility if to write a small exe, or com or any other form that can send out this special char file just to print out double blank line (\n\n).
and that is exactly the problem .

--- test.bat , place in /cgi-bin/
@echo off
echo Content-Type: text/html
call out.pl
call out.pl
rem echo <html>
rem echo <head>
rem echo <title>Title</title>
echo a

-- out.pl to be in the same dir as test.bat.  And you need perl around.
#!c:\perl\bin\perl
print "$ARGV[0]\n";

---
This is one quick solution that I can think off.  Well if you had Perl around, why need batch file anyway :)

0
 
LVL 15

Expert Comment

by:samri
ID: 7100038
OK, the \n\n, can be done with echo. (no space between echo and .)

so
---
@echo off
echo Content-Type: text/html
echo.
echo.
---

Should give a proper HTTP Header.

But the problem still on how to print out HTML TAG; ie <HEAD> etc.etc.  The DOS shell seems to complain about the redirection.
0
 
LVL 15

Accepted Solution

by:
samri earned 50 total points
ID: 7100057
Haha... I got it.

Make sure you had sl.txt, gt.txt, st.txt, where the files would contains a single >,<,/ or any html quoting (or whatever).

gt.txt contain >
st.txt contain <
sl.txt contain /
you can add more.

--- it's kinda of fun.

the batch file.
------------
@echo off
echo Content-Type: text/html
echo.
echo.
type st.txt
echo HTML
type gt.txt

type st.txt
echo HEAD
type gt.txt

type st.txt
echo TITLE
type gt.txt

echo This is my Title
type st.txt
type sl.txt
echo TITLE
type gt.txt

type st.txt
echo BODY
type gt.txt

echo Whatever your body is
type st.txt
type sl.txt
echo BODY
type gt.txt

type st.txt
type sl.txt
echo HTML
type gt.txt
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Author Comment

by:Triskelion
ID: 7107117
Interesting
0
 
LVL 15

Expert Comment

by:samri
ID: 7107993
Out of curiosity,

Do you happens to have any requirement that requires DOS batch file to be CGI enabled?

Very interesting thought sometime.  Btw, did you ever wonder how would other languages behaves, COBOL for example ?
0
 
LVL 6

Author Comment

by:Triskelion
ID: 7108035
No.  I was just playing around.
As a matter of fact, I was experimenting with PASCAL and ASM when I thought about the DOS batch issue.

It should be possible to make a CGI with anything that can produce the correct output.
I did, however, run across a problem when experimenting with ASM.  Here is a link to the question:
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cgi&qid=20314840
0
 

Expert Comment

by:polebridge
ID: 8599405
you can use ^ (shift-6) to escape the < and >
For example:
echo ^<html^>
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now