Solved

CGI with Dos batch?

Posted on 2002-06-21
7
345 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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

840 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