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

stdin or something like readln (ARGHH!)

0 views
Skip to first unread message

Benny Pedersen

unread,
Jun 20, 2002, 3:09:06 AM6/20/02
to

"John Martin" <John....@camtronics.com> wrote news:Ws3Q8.2$6M5.134@client...
> anybody know of a quick and dirty way to get user input during a batch file
> execution. I know about "choice", and of course there is "pause" that
> waits for the famous 'any key' and also the command line entries %1 et.al.,
> but what I would like is a way to get a text line (without resorting to a
> perl script,etc) in the middle of the batch file.
>
> please respond via e-mail, as I dont monitor this group.
>
> thanx,
> john


This one was hard to find, (line numb 4 won't work without a ^ as ^1 and
that's very strange?). Moreover, an ASCII 13 was needed in WinNT and the
character of ASCII value 10 in Win9X. ARGHHH! anyhow I found a solution.

Benny Pedersen,

@echo off
echo wScript.createObject("wScript.shell").run"%comSpec%"_>%temp%.\~.vbs
echo +" /cEcho set i=" +inputBox("Prompt","?","Default")_>>%temp%.\~.vbs
if Windows_NT==%OS% echo +chr(13)+">""%temp%.\~.bat",0,^1>>%temp%.\~.vbs
if Win9X==Win9X%OS% echo +chr(10)+">""%temp%.\~.bat",0, 1>>%temp%.\~.vbs

if Win9X==Win9X%OS% start.exe/wait wScript.exe %temp%.\~.vbs
if not Win9X ==%OS%Win9X %temp%\~.vbs

call %temp%.\~.bat
echo. You input was %i%

set i=
for %%e in (bat vbs) do del %temp%.\~.%%e
pause
cls

John Martin

unread,
Jun 20, 2002, 9:18:14 AM6/20/02
to
thanks for all the input!!! I'll play around with them. I neglected to
mention that I use NT&2k so it looks like the 'fc' examples wont work for
me.

thanx,

john

"Benny Pedersen" <b.ped...@get2net.dk> wrote in message
news:UdfQ8.15$PD4...@news.get2net.dk...

Curtis Anderson

unread,
Jun 20, 2002, 4:49:29 PM6/20/02
to
Benny Pedersen wrote:
> "John Martin" <John....@camtronics.com> wrote news:Ws3Q8.2$6M5.134@client...
>
>>anybody know of a quick and dirty way to get user input during a batch file
>>execution. I know about "choice", and of course there is "pause" that
>>waits for the famous 'any key' and also the command line entries %1 et.al.,
>>but what I would like is a way to get a text line (without resorting to a
>>perl script,etc) in the middle of the batch file.

If you want REALLY quick and REALLY dirty, use good ol'
COPY CON %TEMP%\workfile.txt
then use the resulting file to do whatever you need.
This does require the user to press F6 and ENTER to save the file though.
eg)
REM NT server:
REM Check licenses via ControlPanel/License tool (GUI)
Echo Checking Licenses
Echo Checking Licenses >>%INVLOGFILE%
Echo Enter license type and amount, then press F6 and Enter.
control liccpa.cpl
copy con %TEMP%\workfile.txt >nul
type %TEMP%\workfile.txt >>%INVLOGFILE%
Echo.>>%INVLOGFILE%
del %TEMP%\workfile.txt

Sam Wigley

unread,
Jun 20, 2002, 5:49:17 PM6/20/02
to
"Benny Pedersen" <b.ped...@get2net.dk> wrote in message news:<UdfQ8.15$PD4...@news.get2net.dk>...


I found that there is an easy way to do this if you are using Windows
2000 or XP. This doesn't work with DOS or WIN95/NT. You can use the
new /p Switch for the set command to prompt for user input. Here's
how it works:

set /p varname="text string prompt"

So, if you put set /p color="What is your favorite color: " in your
batch file.
you will get a prompt that says, "What is your favorite color: " and
it will wait for user input. If the user enters blue, the variable
color will be set to "blue". I think this is the preferred method,
unless you have to use an older version of dos. I spent alot of time
trying to set variables in dos from user input, and I wound up writing
a utility that just does that. It prompts for input and sets an
environment variable. I like the new set /p option, but I wish it was
ther earlier. It shouldn't be a difficult thing to set a variable
from user input.

John Martin

unread,
Jun 20, 2002, 5:45:29 PM6/20/02
to
yes I knew about that too...just trying to keep it a bit simpler for the
user.
-john

"Curtis Anderson" <ned...@hotmail.com> wrote in message
news:3D123FD...@hotmail.com...

Charles Dye

unread,
Jun 20, 2002, 6:58:30 PM6/20/02
to
"Benny Pedersen" <b.ped...@get2net.dk> wrote in message news:<UdfQ8.15$PD4...@news.get2net.dk>...

> This one was hard to find, (line numb 4 won't work without a ^ as ^1 and
> that's very strange?).

> if Windows_NT==%OS% echo +chr(13)+">""%temp%.\~.bat",0,^1>>%temp%.\~.vbs

Remember, 1>> is a valid redirection operator in most post-COMMAND.COM
shells. Simply inserting a space between the 1 and the >> should make
your meaning unambiguous.

--
Charles Dye ras...@highfiber.com

Todd Vargo

unread,
Jun 20, 2002, 7:01:27 PM6/20/02
to

"John Martin" <John....@camtronics.com> wrote in message
news:j1sQ8.6$TV5.172@client...

> yes I knew about that too...just trying to keep it a bit simpler for the
> user.
> -john

Users don't care how something is programmed, just that it works, and that
it's bug free. Now that your talking multiple OS's, your not talking
quick_and_dirty batch code any more either. If you need this batch solution
for distribution, then you really need to define _ALL_ of the parameters of
the problem so an informed suggestion can be offered.

Some thoughts to ponder...

What is the purpose for the user input?
What is the range of input characters allowed?
Are 3rd party utilities allowed?
What OS is the target audience using?
What is the purpose of the BATCH?
Does it really have to be programmed with BATCH code?

--
Todd Vargo (body of message must contain my name to reply by email)

Benny Pedersen

unread,
Jun 20, 2002, 10:38:51 PM6/20/02
to

"Charles Dye" <ras...@highfiber.com> wrote news:3c3ff09a.02062...@posting.google.com...

--
Yes, that I know but I got the space included.
Remember, that I'm a newbee. (thanks).

While the inputBox is waiting to take your input, DOS displays
it's ugly, black window. To avoid that, minimize the program with
use of the: start/min %comSpec% /c"%0". If you later want the
DOS Window to be maximized, just repeat the Command Start with
use of the /max switch.

The previous solution for creating the script, used two lines: One for
WinNT and one for Win9X. Anyhow, the whole Script is a ONLY-One-Line-
solution that was wrapped with use of underScores (_), readable for
the Usenet. WSH knows how to assemble those pieces
into the ONLY one line.

Thereby, I want to find a better solution, which could
be used in all systems (OS).
The previous char(13) was a BAD method but seems to be needed when
the input was an integer. Anyhow, a single space before the
greater than (>) solves that problem but the input was then
appended with that space, so, the appropriate syntax to get an input
with GUI support for all systems, would be this, ONLY one line:
(Please unWrap),

echo.wScript.createObject("wScript.shell").run"%comSpe
c% /c>%temp%.\~.bat echo.set i="+inputBo
x("Prompt","?","Default"),0,1.>%temp%.\~.vbs

AND all problems was solved within both OS: Win9X and WinNT.


Details about the above ,0,1. (last line),
------------------------------------------
The zero is used to let DOS, NOT showing it's ugly face.
The ,1 (default is zero), is used to wait, i.e. the
program won't continue to early but is waiting.
The dot in 1. is used to avoid the ^ character with
Windows NT but is also working perfect within Windows 9X.
No space would be included like, (i ).

Special inputs such as pipe (|), etc.,
--------------------------------------

Modification like this:
set i="""+inputBox("Prompt","?","Default")+"""",0,1.
(the first quote is substituted with 3 quotes and the
,0,1. got prefixed with +four quotes).


@echo off
%1 start/min %comSpec% /c"%0" goto:Script
exit

: Script
echo.wScript.createObject("wScript.shell").run"%comSpec% /c>%temp%.\~.bat echo.set
i="+inputBox("Prompt","?","Default"),0,1.>%temp%.\~.vbs
goto %OS% Windows_9X

: Windows_NT
::for %%C in (cal de) do for %%E in (vbs bat) do %%CL %temp%.\~.%%E
::start/max %comSpec% /t:f0/k"%0" goto:Common&&exit

REM Those two lines above is working in NT but since the below would
REM works for both OS, I then disabled the above.
REM Notice that the nested FOR loops don't need: DO %comSpec%/cFOR :)

: Windows_9X
start/wait wScript.exe %temp%.\~.vbs
call %temp%.\~.bat
for %%E in (vbs bat) do del %temp%.\~.%%E
start/max %comSpec% /c"%0" goto:Common %i%
exit

REM The "%i% to %2" (instead of: You input was %i%) is needed in 9X.

: Common
echo.
echo. You input was %2
echo.
set i=
pause
cls
exit

:: Benny Pedersen, http://2dos.homepage.dk
:: End of InputBox in ONE line for all OS.


Benny Pedersen

unread,
Jun 21, 2002, 1:29:44 AM6/21/02
to

"Benny Pedersen" <b.ped...@get2net.dk> wrote news:6mwQ8.801$PD4....@news.get2net.dk...
---

Hi,

The following should be more readable and so but I have only
tested in Win9X.
(See some nice tricks later under the below PS.PS. and BTW.)

@echo off
%1 for %%C in (start goto:EOF) do %%C /min %com
Spec% /c"%0" goto:Begin

: Begin
echo.wScript.createObject("wScript.shell").run"%com
Spec% /c>%temp%.\~.bat echo.set i="+inputBox("Pro


mpt","?","Default"),0,1.>%temp%.\~.vbs

start/wait wScript.exe %temp%.\~.vbs
call %temp%.\~.bat

start/max %comSpec% /c"%0" goto:Maximized %i%
set i=


for %%E in (vbs bat) do del %temp%.\~.%%E

exit[MinComSpec]

: Maximized
echo.
echo. [input] = [%2]
for %%C in (echo pause cls exit[MaxComSpec]) do %%C.

Benny Pedersen,
PS. (Three lines was wrapped).
PS.PS. The label named Maximized, probably do not need to be used.
Use 1 of the following (The Ugly, The Nice or The OOPS) instead:

%Ugly% start/max %comSpec% /cfor %%C in (pro
mpt:$ cls pause"[input]=[%i%]>nul") do %%C
%Nice% start/max %comSpec% /cfor %%C in ("pro
mpt:[input]=[%i%]$_$_" "cls>con" pause) do %%C
%OOPS% start/max %comSpec% /cfor %%C in ("pro
mpt:$_[input]=[%i%]$_>nul" cls pause :) do %%C

BTW. in order to include the prefixed %Description%, leave those as
blank without setting a variable such as, for example:
SET Ugly=Mother-in-law.

John Martin

unread,
Jun 21, 2002, 10:28:52 AM6/21/02
to
this is exactly what I was looking for - quick and dirty - and I dont need
all the extra command environments and minning/maxxing, I wanted the var in
the original command environment.

echo.wScript.createObject("wScript.shell").run"%comSpec% /c>%temp%.\~.bat

echo.set inputvalue="+inputBox("Enter
Value","?","Default"),0,1.>%temp%.\~.vbs


wScript.exe %temp%.\~.vbs
call %temp%.\~.bat

thanx again for all the help!!! :-)

-john

"Benny Pedersen" <b.ped...@get2net.dk> wrote in message

news:fSyQ8.2$ZA5...@news.get2net.dk...

Bill Stewart

unread,
Jun 21, 2002, 1:08:48 PM6/21/02
to
"John Martin" <John....@camtronics.com> wrote
news:Ws3Q8.2$6M5.134@client...

> anybody know of a quick and dirty way to get user input during a batch
file
> execution. I know about "choice", and of course there is "pause" that
waits
> for the famous 'any key' and also the command line entries %1 et.al., but
> what I would like is a way to get a text line (without resorting to a
perl
> script,etc) in the middle of the batch file.

Try my getvar.exe.

http://mywebpages.comcast.net/stewartb/files/getkv7.zip


0 new messages