Jump to content











Photo
- - - - -

how do I input variable in dos batch


  • Please log in to reply
10 replies to this topic

#1 jtan

jtan

    Newbie

  • Validating
  • 17 posts
  •  
    Canada

Posted 28 October 2010 - 11:47 PM

Hi,

I cannot get the following code to work in win98 or winME dos.


set x=1

set /p x=enter new x number <----- this command does work in xp run cmd

echo %x%


======================

Anyhow is there a way for win98 dos to accept input of a string or number ?

#2 amalux

amalux

    Platinum Member

  • Tutorial Writer
  • 2813 posts
  •  
    United States

Posted 29 October 2010 - 12:45 AM

Yeah, pre 2000 DOS was limited, no set /p. There's some stuff here but looks pretty hairy:
http://www.robvander...m/userinput.php

Why are you stuck in win98/me? :)

#3 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13750 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 29 October 2010 - 07:16 AM

Nothing "hairy".

Win9x/Me has choice.

You use it.

The only "problematic" OS without third party files is NT 4.0, but there are tens of suitable apps to get user input, besides a few "tricks":
http://www.robvander...b_userinput.php

You can also check the "NT like" command processor for Win9x/Me systems, but cannot say if it also offers SET /P:
http://www.boot-land...?showtopic=2392
http://cygutils.fruitbat.org/consize/

:)
Wonko

#4 amalux

amalux

    Platinum Member

  • Tutorial Writer
  • 2813 posts
  •  
    United States

Posted 29 October 2010 - 06:05 PM

Win9x/Me has choice.

You use it.

OK, I'll bite, where? I was too tired to look last night but have since and can find no example. I don't even have choice.exe in my path, host or PE. You know I like js and vbs for user input but where needed I have used similar to following examples in batch:
@echo off

set /p drive=Enter a drive letter where you want &#39;Drivers&#39; folder to be located&#58; 

echo. 

for %%d in &#40;a b c d e f g h i j k l m n o p q r s t u v w x y z&#41; do &#40;

if &#34;%drive%&#34;==&#34;&#34; &#40;echo Let&#39;s try that again...&#41; & &#40;goto drive&#41; 

if /I &#34;%drive%&#34;==&#34;%%d&#34; &#40;goto setdir&#41;

&#41;
@echo off

echo No drivers source was found. How do you want to proceed?

echo.

echo.

echo   &#91;1&#93; Choose a directory and run driver import.

echo.

echo   &#91;2&#93; Auto create directory and import host drivers.

echo.

echo   &#91;Q&#93; Quit

echo.

echo.

set choice=

set /p choice=  Make your selection and press Enter &#58;

echo.

if not &#39;%choice%&#39;==&#39;&#39; set choice=%choice&#58;~0,1%

if /i &#39;%choice%&#39;==&#39;1&#39; call rescan.cmd

if /i &#39;%choice%&#39;==&#39;2&#39; call sdbdipe.cmd

if /i &#39;%choice%&#39;==&#39;Q&#39; goto end



&#58;end

exit

I even found an old one I used to use:
@ECHO OFF

&#58;LOOP

SET /P USERPARM=Enter the Value &#58;



IF &#34;%USERPARM%&#34;==&#34;&#34; &#40;

ECHO Nothing is entered

GoTo &#58;LOOP

&#41;

IF /I &#34;%USERPARM%&#34;==&#34;Y&#34; &#40;

ECHO Success

&#41; ELSE &#40;

IF /I &#34;%USERPARM%&#34;==&#34;N&#34; &#40;

ECHO Failure

&#41; ELSE &#40;

ECHO The param entered is not Y/y nor N/n

&#41;

&#41;
but all these use set /p which won't work for the OP.

What's strange is that I do remember using something like this in the past but can't find where (or know how it would work without choice in path).
@ECHO OFF

&#58;BEGIN

CLS

REM - THE BELOW LINE GIVES THE USER 3 CHOICES &#40;DEFINED AFTER /C&#58;&#41;

CHOICE /N /C&#58;123 PICK A NUMBER &#40;1, 2, or 3&#41;%1

REM - THE NEXT THREE LINES ARE DIRECTING USER DEPENDING UPON INPUT

IF ERRORLEVEL ==3 GOTO THREE

IF ERRORLEVEL ==2 GOTO TWO

IF ERRORLEVEL ==1 GOTO ONE

GOTO END

&#58;THREE

ECHO YOU HAVE PRESSED THREE

GOTO END

&#58;TWO

ECHO YOU HAVE PRESSED TWO

GOTO END

&#58;ONE

ECHO YOU HAVE PRESSED ONE

&#58;END
So I'm willing to look silly here, where do I call choice.exe in my batch files?

I really just want to offer an example to jtan so if I have one somewhere I'd like to know :cheers:

:cheers:

#5 Aye Htay

Aye Htay

    Frequent Member

  • Advanced user
  • 163 posts
  •  
    Myanmar

Posted 29 October 2010 - 06:18 PM

,,,,,,,, :cheers:

Why don't you directly ask to batch files master (Wonko)? :cheers: :cheers:

ah

#6 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13750 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 29 October 2010 - 07:09 PM

I'll try again. :cheers:

The DOS (and Windows 9x/Me) command interpreter COMMAND.COM has NOT (and NEVER had) a SET /P option, not any INTERNAL command capable of accepting user input.

Since the dawn of time (like DOS 1.0, if ever existed) there was an external command CHOICE.COM. (in some later versions it became a .exe CHOICE.EXE)
With NT 4.00 Microsoft (in it's usual approach to easen lives of their clients) REMOVED CHOICE from the OS distribution (and put it in the SDK) WITHOUT providing the SET /P option.

http://winsupport.or...dos-choice.html

Soon everyone started to write CHOICE substitutes or anyway other means to have user input in batches. (usually better than original CHOICE.COM/CHOICE.EXE, most notable being CHOIX.EXE):
http://www.ultimateb...opic.php?t=1422

With Windows 2K Microsoft finally introduced the SET /P.

CHOICE use is straightfoward, you run it with parameters and check the ERRORLEVEL:
http://www.robvander....com/choice.php
but it's use is akward when compared to the SET /P capabilities.

Please remember that a number of things you are used to in NT/2K/XP and later simply DO NOT exist in DOS batch programming/syntax.

At the bottom of this page there are also links to more third party apps that you can use in "pure" DOS:
http://www.robvander...m/userinput.php
Worth a mention is the (graphical) WBAT:
http://home.mnet-onl...orst.muc/ui.htm

:cheers:
Wonko

#7 amalux

amalux

    Platinum Member

  • Tutorial Writer
  • 2813 posts
  •  
    United States

Posted 29 October 2010 - 07:31 PM

Thank you Wonko, you know I love your history lessons and I do learn much from the master to be sure :cheers: but in this case it seems to miss the point. I was only responding to your assertion that I use choice, I wasn't aware of if I do and wanted an example; maybe you meant jtan uses choice :cheers: . If so, I clearly mis-understood and apologize for wasting the masters time :cheers:

Anyway, I really just wanted to help jtan and you've certainly given him plenty of options to try so no harm done. Thanks again for sharing your wealth of knowledge and for all you do.

:cheers:

#8 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13750 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 29 October 2010 - 07:40 PM

I was only responding to your assertion that I use choice, I wasn't aware of if I do and wanted an example; maybe you meant jtan uses choice :cheers: .


Well, what I meant by:

Win9x/Me has choice.

You use it.

was "generic". :cheers:

It can be rephrased as:

Since Dos/Win9x/Me has no provision for SET /P you (meaning ANYONE needing to have user input in a batch intended to be run under Dos/Win9x/Me) use the CHOICE external command.


As a paragon:

Since in 1776 cars were NOT invented yet, when making an historical reconstruction of the Battle of Trenton you use a horse, or a horse driven carriage, or your own feet, like anyone else has done for several centuries before 1776.



... and yes, horses tend to be "more hairy" then cars... :cheers:
:cheers:

There are exceptions of course :cheers::
http://www.equestria...ts.asp?TID=1040



:cheers:
Wonko

#9 Rui Paz

Rui Paz

    Frequent Member

  • Advanced user
  • 201 posts
  •  
    Portugal

Posted 30 October 2010 - 11:17 AM

Hi,

I cannot get the following code to work in win98 or winME dos.


set x=1

set /p x=enter new x number <----- this command does work in xp run cmd

echo %x%


======================

Anyhow is there a way for win98 dos to accept input of a string or number ?


Hi,

If you are on Win9x Batchs i highly recommend you to install 4dos its now free for Win9x and DOS, this alternative shell will give you much powerful commands and if i'm not mistaken it includes SET command and also lots of other useful commands.
http://www.4dos.info/v4dos.htm

#10 jtan

jtan

    Newbie

  • Validating
  • 17 posts
  •  
    Canada

Posted 01 November 2010 - 09:23 PM

Hi

First of all, I would like to thank everyone for their suggestion.

I finally use this input.exe utility and it work in windows98 / windowsME.


http://home.mnet-onl...t.muc/horst.htm
(INPUT 1.2 string input, editing of existing variable.. )

set x=1
set y=

input " * enter new x value " y
echo %y%

set y = %x% <---- how do i set y = x if y is not blank or return key?


Please advice and THanks.

Edited by jtan, 01 November 2010 - 09:27 PM.


#11 jtan

jtan

    Newbie

  • Validating
  • 17 posts
  •  
    Canada

Posted 01 November 2010 - 10:34 PM

Nevermind I figured it out :cheers:


set x=1

input " enter new x " x /E /L4

echo %x%


============================

-----------------------------------------------------------------------
INPUT String input/editing ver 1.2 © 2001 Horst Schaeffer
------------------------------------------------------------------------
Note: INPUT does not work under Win NT/2000/XP

INPUT prompts for a string input and returns the result in an
environmental variable. The current variable my be offered for
editing or confirmation.

INPUT has its own edit handling, and does not use the standard DOS
string input function.

Syntax: INPUT [line,column] [prompt] varname [options]


line,column sets cursor (1...) for the prompt string. Default is the
current cursor position.

prompt enclosed in (single or double) quotes.
By default the input field begins right after the prompt.
Add blank space(s) to the prompt string for offset.

varname name of variable for the string.

options:
/E edit: the current string (varname) will be offered for
editing or confirmation. Cursor at beginning of field.

/S edit with special handling: cursor set to end of string;
any character key will clear the input field (other keys,
like cursor movements will allow editing).

/Ln limit input length=n. Default (and maximum) is up to the
rightmost column minus 1.

/U upper case
/I insert mode
/N only numeric input accepted
/P password mode (make sure to clear variable before)
/F flush input buffer
/C allow Ctrl+Break




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users