Ask questions in Batch file until valid response is made

View: New views
9 Messages — Rating Filter:   Alert me  

Ask questions in Batch file until valid response is made

by bobrashear :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How do you put the script in a 'loop' (re-ask the same question) when
an invalid response is made in the batch file?

For example, if you want either a "Y" or "N" response and someone
accidentally types a response of something else (like "T" or "M").

If an invalid selection is made, I'd like the batch file to ask the
question until a valid answer is made.

Any help is GREATLY appreciated!!!


Re: Ask questions in Batch file until valid response is made

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 06 Apr 2008 16:05:21 -0000, "bobrashear" <bobrashear@...>
wrote:

>How do you put the script in a 'loop' (re-ask the same question) when
>an invalid response is made in the batch file?
>
>For example, if you want either a "Y" or "N" response and someone
>accidentally types a response of something else (like "T" or "M").
>
>If an invalid selection is made, I'd like the batch file to ask the
>question until a valid answer is made.
>
>Any help is GREATLY appreciated!!!

Here is one way:

@echo off
:a
set "rep="
set "var="
set /p "var= Type your answer [Y/N]: "
if /i (%var%)==(n) set rep=1
if /i (%var%)==(y) set rep=1
if not defined rep (echo oops. Have another shot... &goto :a)


RE: Ask questions in Batch file until valid response is made

by Byrne, Derek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

:: Tested - db

:: In the following program, the :: is the equivalent to the REM
statement.

:: Just copy and paste this whole prog into a batch file and run.

:: Only an answer of Y, y, N or n will get you to the end.

:: All other responses should produce an error and ask the question
again.

 

@echo off

setlocal

:: Clear the screen

cls

:: This initialises the RESPONSE variable

set RESPONSE=

:: This is where we loop

:LOOP

:: Ask a silly question

Echo Hello, do you wish to format your hard drive? (Y/N)

:: This pauses the process, allowing the user to enter in a value.

Set /p RESPONSE=

:: If the response equals YES, then echo this out and jump to the end

if /i "%RESPONSE%" EQU "Y" echo So you want to Format your Hard Drive??
Are you Mad??&&echo.&&goto :NEXT

if /i "%RESPONSE%" EQU "y" echo So you want to Format your Hard Drive??
Are you Mad??&&echo.&&goto :NEXT

 

:: If the response equals NO, then echo this out and continue

if /i "%RESPONSE%" EQU "N" echo Good choice :o)&&echo.&&goto :NEXT

if /i "%RESPONSE%" EQU "n" echo Good choice :o)&&echo.&&goto :NEXT

 

:: this says: "if the response doesn't equal Y or y or N or n, then jump
back to the LOOP stage

if /i "%RESPONSE%" NEQ "Y" echo Incorrect Entry&&echo.&&goto :LOOP

if /i "%RESPONSE%" NEQ "y" echo Incorrect Entry&&echo.&&goto :LOOP

if /i "%RESPONSE%" NEQ "N" echo Incorrect Entry&&echo.&&goto :LOOP

if /i "%RESPONSE%" NEQ "n" echo Incorrect Entry&&echo.&&goto :LOOP

 

:NEXT

endlocal

pause

 

 

Kind regards,

 

Derek Byrne
IT Retail Field Engineer

 

  <http://www.meteor.ie/>


E: derek.byrne@... <mailto:derek.byrne@...>
P: 01 - 430 7398
M: 085-711 7398

 

From: batchworld@... [mailto:batchworld@...] On
Behalf Of bobrashear
Sent: 06 April 2008 17:05
To: batchworld@...
Subject: [BATCH WORLD] Ask questions in Batch file until valid response
is made

 

How do you put the script in a 'loop' (re-ask the same question) when
an invalid response is made in the batch file?

For example, if you want either a "Y" or "N" response and someone
accidentally types a response of something else (like "T" or "M").

If an invalid selection is made, I'd like the batch file to ask the
question until a valid answer is made.

Any help is GREATLY appreciated!!!

 

******************************************
Meteor Mobile Communications Limited, trading as Meteor.
Registered Office: 4030 Kingswood Avenue, Citywest Business Park, Naas Road, Dublin 24, Ireland.
Registered in Ireland: 282645

 
DISCLAIMER: This email and its attachments contain confidential information and may be legally privileged. The message is intended only for the addressee(s) stated above.  If you are not the named addressee(s) or intended recipient please do not use, copy, disseminate or disclose the information to anyone.  If you have received this email in error please immediately notify the sender at Meteor and delete the material from any system and destroy any copies.
******************************************


[Non-text portions of this message have been removed]


Accessing a shared file within a bat file

by Gary Kuznitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm having a problem running a bat file in XP Pro.  I'm running it with:

RUNRMTCMD CMD('C:\BATCH\SCAN.BAT 00155900000.TIF') RMTLOCNAME('192.168.1.4'
*IP) RMTUSER('B') RMTPWD(hidden)
The above command is run from computer A on computer B.

The bat file that runs on computer B looks like this:
C:\Batch\hstart.exe /NOWINDOW /D=C:\PROGRA~1\IRFANVIEW
"C:\PROGRA~1\IRFANVIEW\I_VIEW32 \\Atu1277\SCANS\%1"

The above is on one line.

The error I get is:

\\Atu1277\SCANS\00155900000.TIF : Can't read file header !
Unknown file format or file not found.

At that point the program I_view32 is still up and running. It was called with
a user (SCANS) that is not signed on.  If I click on Open and navigate to the
same file it works just fine.

What could I be doing wrong?
The folder SCANS is shared.  Is there something special I need to do to access
as shared file within a bat file?

Thank you,

Docfxit

Re: Accessing a shared file within a bat file

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 01 May 2008 22:16:46 -0700, "Gary Kuznitz" <docfxit@...>
wrote:

>I'm having a problem running a bat file in XP Pro.  I'm running it with:
>
>RUNRMTCMD CMD('C:\BATCH\SCAN.BAT 00155900000.TIF') RMTLOCNAME('192.168.1.4'
>*IP) RMTUSER('B') RMTPWD(hidden)
>The above command is run from computer A on computer B.
>
>The bat file that runs on computer B looks like this:
>C:\Batch\hstart.exe /NOWINDOW /D=C:\PROGRA~1\IRFANVIEW
>"C:\PROGRA~1\IRFANVIEW\I_VIEW32 \\Atu1277\SCANS\%1"
>
>The above is on one line.
>
>The error I get is:
>
>\\Atu1277\SCANS\00155900000.TIF : Can't read file header !
>Unknown file format or file not found.
>
>At that point the program I_view32 is still up and running. It was called with
>a user (SCANS) that is not signed on.  If I click on Open and navigate to the
>same file it works just fine.

Does it work if the user SCANS is signed on?

>What could I be doing wrong?
>The folder SCANS is shared.  Is there something special I need to do to access
>as shared file within a bat file?

If I recall correctly the default system account does not have network
access.


Re: Accessing a shared file within a bat file

by Gary Kuznitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the reply.

On 2 May 2008 at 18:35, foxidrive (foxidrive <batchworld@...>) commented about Re: [BATCH WORLD] Accessing a share:

> On Thu, 01 May 2008 22:16:46 -0700, "Gary Kuznitz" <docfxit@...>
> wrote:
>
> >I'm having a problem running a bat file in XP Pro.  I'm running it with:
> >
> >RUNRMTCMD CMD('C:\BATCH\SCAN.BAT 00155900000.TIF') RMTLOCNAME('192.168.1.4'
> >*IP) RMTUSER('B') RMTPWD(hidden) The above command is run from computer A on
> >computer B.
> >
> >The bat file that runs on computer B looks like this:
> >C:\Batch\hstart.exe /NOWINDOW /D=C:\PROGRA~1\IRFANVIEW
> >"C:\PROGRA~1\IRFANVIEW\I_VIEW32 \\Atu1277\SCANS\%1"
> >
> >The above is on one line.
> >
> >The error I get is:
> >
> >\\Atu1277\SCANS\00155900000.TIF : Can't read file header !
> >Unknown file format or file not found.
> >
> >At that point the program I_view32 is still up and running. It was called with
> >a user (SCANS) that is not signed on.  If I click on Open and navigate to the
> >same file it works just fine.
>
> Does it work if the user SCANS is signed on?
It did work when I had it configured with a mapped drive.  It doesn't work now
when I'm signed on with the user SCANS.
 
> >What could I be doing wrong?
> >The folder SCANS is shared.  Is there something special I need to do to access
> >as shared file within a bat file?
>
> If I recall correctly the default system account does not have network
> access.  

I'm using the SCANS user account not the guest account.  SCANS has
Administrator privileges.

Maybe network access has something to do with it.  Do you know how to fix that?

Thank you,

Gary Kuznitz
 

Re: Accessing a shared file within a bat file

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 05 May 2008 19:26:04 -0700, "Gary Kuznitz" <docfxit@...>
wrote:

>> >I'm having a problem running a bat file in XP Pro.  I'm running it with:
>> >
>> >RUNRMTCMD CMD('C:\BATCH\SCAN.BAT 00155900000.TIF') RMTLOCNAME('192.168.1.4'
>> >*IP) RMTUSER('B') RMTPWD(hidden) The above command is run from computer A on
>> >computer B.
>> >
>> >The bat file that runs on computer B looks like this:
>> >C:\Batch\hstart.exe /NOWINDOW /D=C:\PROGRA~1\IRFANVIEW
>> >"C:\PROGRA~1\IRFANVIEW\I_VIEW32 \\Atu1277\SCANS\%1"
>> >
>> >The above is on one line.
>> >
>> >The error I get is:
>> >
>> >\\Atu1277\SCANS\00155900000.TIF : Can't read file header !
>> >Unknown file format or file not found.

As it worked with a mapped drive then perhaps irfanview doesn't grok UNC
paths.

Try just the batch

"C:\PROGRA~1\IRFANVIEW\I_VIEW32 \\Atu1277\SCANS\%1"

on a local machine and see if it has the same issue.


Parent Message unknown Re: Accessing a shared file within a bat file

by Gary Kuznitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the reply.

On 6 May 2008 at 19:38, foxidrive (foxidrive <batchworld@...>) commented about Re: [BATCH WORLD] Accessing a shared file within :

> On Mon, 05 May 2008 19:26:04 -0700, "Gary Kuznitz" <docfxit@...>
> wrote:
>
> >> >I'm having a problem running a bat file in XP Pro.  I'm running it with:
> >> >
> >> >RUNRMTCMD CMD('C:\BATCH\SCAN.BAT 00155900000.TIF') RMTLOCNAME('192.168.1.4'
> >> >*IP) RMTUSER('B') RMTPWD(hidden) The above command is run from computer A on
> >> >computer B.
> >> >
> >> >The bat file that runs on computer B looks like this:
> >> >C:\Batch\hstart.exe /NOWINDOW /D=C:\PROGRA~1\IRFANVIEW
> >> >"C:\PROGRA~1\IRFANVIEW\I_VIEW32 \\Atu1277\SCANS\%1"
> >> >
> >> >The above is on one line.
> >> >
> >> >The error I get is:
> >> >
> >> >\\Atu1277\SCANS\00155900000.TIF : Can't read file header !
> >> >Unknown file format or file not found.
>
> As it worked with a mapped drive then perhaps irfanview doesn't grok UNC
> paths.
>
> Try just the batch
>
> "C:\PROGRA~1\IRFANVIEW\I_VIEW32 \\Atu1277\SCANS\%1"
>
> on a local machine and see if it has the same issue.

It has the same error.

I looked into your suggestion of maybe the network is not available to a user
that is not logged in.  Someone else had a solution.  I adapted it to this
install and ran a test with this bat file:

Start of bat file:
::ListScansFiles -- this script will list the files from L: drive.
::                        
 @echo off
 SETLOCAL ENABLEEXTENSIONS
 SETLOCAL ENABLEDELAYEDEXPANSION
 echo execution of ListScansFiles started  %date%-%time% >>  
C:\SCRATCH\ListScansFiles.log
 net use L: \\ATU1277\Scans <password> /user:b persistance=no
 L:
 cd \
 for %%F in (*.*) do (
    echo ***** %%~nxF Exist in L:\  >> C:\SCRATCH\ListScansFiles.log *****
 )
 echo execution of ListScansFiles ended %date%-%time% >>  
C:\SCRATCH\ListScansFiles.log
 C:
 net use L: /delete
 exit
End of Bat file.  If a line starts in Column one it wrapped.

I expected it to list all the files in \\ATU1277\Scans.
Instead it listed all the files on the C: drive of the local machine.

This is only meant for a test to see if I can connect to the network.

Any ideas why it didn't list the network drive?

Thank you,

Gary Kuznitz



Re: Accessing a shared file within a bat file

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 06 May 2008 13:30:10 -0700, "Gary Kuznitz" <docfxit@...>
wrote:

> net use L: \\ATU1277\Scans <password> /user:b persistance=no

Your command syntax looks to be wrong.


/PERSISTENT:NO





NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]


LightInTheBox - Buy quality products at wholesale price