Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

emulate "cat <<EOF" in dos (batch or not)

2,181 views
Skip to first unread message

gvandelaer

unread,
Jun 4, 2003, 7:13:29 AM6/4/03
to

> [ Followups set to: alt.msdos.batch.nt ]
>
>Djeezus wrote:
>
>> I'm writing a script to be run on "WinNT4.0"
>
>You do not have DOS, you have one of Microsoft's
>non-DOS operating systems. In future please post
>your questions to an appropriate newsgroup.
>
>news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
>news:alt.msdos.batch.nt
>OR
>http://groups.google.com/groups?as_ugroup=alt.msdos.batch.nt

I'm sorry about not getting the correct group, but I think it can be
seen as a general question about stdin usage in DOS, wether this be
DOS, QDOS, NTDOS, Win2KDOS ... I just assumed that this part of the os
would be the same on every DOS?

Does this mean that some versions of DOS do have support for <<EOF
style stdin usage ?

bye,
gErT

Garry Deane

unread,
Jun 4, 2003, 8:19:28 AM6/4/03
to
On Wed, 04 Jun 2003 13:13:29 +0200, gvandelaer
<gert.va...@medisearch-int.com> wrote:

>
>I'm sorry about not getting the correct group, but I think it can be
>seen as a general question about stdin usage in DOS, wether this be
>DOS, QDOS, NTDOS, Win2KDOS ... I just assumed that this part of the os
>would be the same on every DOS?
>
>Does this mean that some versions of DOS do have support for <<EOF
>style stdin usage ?

I've seen your thread in alt.msdos.batch but not really been able to
figure out what it is you're trying to do. I know nothing about unix
but from what I can deduce from your earlier posts, there's nothing
equivalent to that <<EOF style of redirection in NT/W2k/XP.

I *think* there might be ways to accomplish what you are after but it
wasn't clear to me what your final batch file should look like.

The usual method for creating a dynamic output file is to repeat the
"ECHO text to be created>>%outfile%" for each line of text you need.
You can also use ">>%outfile% ECHO text to be created"
e.g.

set bak=%comp%.bat
:: locsql.bat contains location of "sqlplus.exe"
:: set locsql="D:\oracle\ora81\bin\SQLPLUS.EXE"
>%bak% echo call c:\msiapps\locsql.bat
>>%bak% echo %locsql% | sed -e "s/$/ name\/pass@msiplanner /g"
>>%bak% echo alter session set nls_language='AMERICAN';
>>%bak% echo alter session set nls_territory='AMERICA';
>>%bak% echo insert into blah.bleh(pcid,soft,ipco,user)
>>%bak% echo values('%pcid%','%soft%','%ipco%','%usr%')
>>%bak% echo exit

To be able to deal with reserved characters like < > ( ) | &, you need
to escape them with ^. Therefore the 2nd last line above would become:

>>%bak%echo values^('%pcid%','%soft%','%ipco%','%usr%'^)

However this might not be quite what you want. I *think* what you want
is to be able to redirect a stream of text to the SQLPLUS.EXE command.
Maybe you can use a technique like the following to create a "DATA"
segment within your batch file, extract that data to a temporary file
then redirect that temporary file to the SQLPLUS command. However this
will only work with static data, you can't use it to expand
environment variables.

:: Example of extracting "data" from a batch file

@echo off
setlocal
set out=%temp%\data.txt
set pcid=1
set soft=2
set ipco=3
set usr=4
type nul > %out%
for /f "tokens=1*" %%a in ('findstr /b ":!" %~f0') do (
>> %out% echo %%b)
>>%bak%echo values('%pcid%','%soft%','%ipco%','%usr%')
>>%bak%echo exit
type %out%|sqlplus

:: Static data goes here preceded by ":!{space}"
:! alter session set nls_language='AMERICAN';
:! alter session set nls_territory='AMERICA';
:! insert into blah.bleh(pcid,soft,ipco,user)

Garry

gvandelaer

unread,
Jun 4, 2003, 8:38:08 AM6/4/03
to
> [ Followups set to: alt.msdos.batch.nt ]
>
>Djeezus wrote:
>
>> I'm writing a script to be run on "WinNT4.0"
>
>You do not have DOS, you have one of Microsoft's
>non-DOS operating systems. In future please post
>your questions to an appropriate newsgroup.
>
>news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
>news:alt.msdos.batch.nt
>OR
>http://groups.google.com/groups?as_ugroup=alt.msdos.batch.nt

I apologize if I posted it to the wrong group,
but trust me ... posting on any microsoft group hasn't done me any
good ever.
I'm just interested in the way DOS handles stdin in specific cases ...
I am aware of the "echo y | del somefile" or "type stuff | find /v
"error" > stuff" and the likes. I've also used the choice and fc
tricks to make a batch interactive via user input ...
but this was just something that I hadn't found a trick for and
perhaps it's something someone is working on ?

Anyway, I've fixed my problem by sedding "echo"'s in front of the
sql-code (and the ">>" at the end of lines).

bye,
gErT

gvandelaer

unread,
Jun 4, 2003, 8:47:57 AM6/4/03
to
Hey Garry,

very interesting stuff you wrote about extracting data from a batch,
but I'm afraid this won't work on Win9x boxes, although I'm sure gonna
use it for cleaning up some code in my other NTscripts.
I've accomplished the same now via sedding echo's in front of the
sql-code like this ...

<snip>
::sofreg.sql contains the sql-code
::locsql.bat contains set %locsql%=c:\foo\bar\sqlplus.exe
echo cd /d c:\msiapps> %comp%.bat
echo call c:\msiapps\locsql.bat >> %comp%.bat
echo del /q %comp%.sql >> %comp%.bat
sed -e "s/^/echo /g;s/$/ \>\> %comp%.sql/g" sofreg.sql >>%comp%.bat
echo %%locsql%% emasterpln_log/csv@msiplanner @c:\msiapps\%comp%.sql
>>%comp%.bat
del sofreg.sql


I was at first thinking along the lines of "type'ing" a file to
"sqlplus.exe" as stdin, but it seems this concept is also limited by
the dos shell.
There's no special oracle-tool available it seems (command line that
is) for DOS to accomplish this :(

Garry Deane

unread,
Jun 4, 2003, 9:25:08 AM6/4/03
to
On Wed, 04 Jun 2003 14:47:57 +0200, gvandelaer
<gert.va...@medisearch-int.com> wrote:

>Hey Garry,
>
>very interesting stuff you wrote about extracting data from a batch,
>but I'm afraid this won't work on Win9x boxes, although I'm sure gonna
>use it for cleaning up some code in my other NTscripts.
>I've accomplished the same now via sedding echo's in front of the
>sql-code like this ...

Ahh, I didn't realise that the batch was running on W9x boxes. I
thought the problem was at the NT4 end.

><snip>
>::sofreg.sql contains the sql-code
>::locsql.bat contains set %locsql%=c:\foo\bar\sqlplus.exe
>echo cd /d c:\msiapps> %comp%.bat
>echo call c:\msiapps\locsql.bat >> %comp%.bat
>echo del /q %comp%.sql >> %comp%.bat
>sed -e "s/^/echo /g;s/$/ \>\> %comp%.sql/g" sofreg.sql >>%comp%.bat
>echo %%locsql%% emasterpln_log/csv@msiplanner @c:\msiapps\%comp%.sql
>>>%comp%.bat
>del sofreg.sql

I still haven't worked out exactly what you are doing (although it's
now clearer) but I'm glad you got it to work with SED.

>I was at first thinking along the lines of "type'ing" a file to
>"sqlplus.exe" as stdin, but it seems this concept is also limited by
>the dos shell.
>There's no special oracle-tool available it seems (command line that
>is) for DOS to accomplish this :(

I think this might be more of a limitation of sqlplus only accepting
input from a file. I take it you've also tried < redirection. I don't
suppose it matters though - I'm pretty sure you'll need to create a
file with your sql commands one way or another so whether you specify
that file on the command line or pipe or re-direct it won't make any
difference.

Garry

0 new messages