batch wait n secs for user to reply

- / -
January 12, 2009 at 23:03:24
Specs: windows xp/2k/nt, -
Greetins

I've tried creating a batch-file that asks the user to give a certain string and wait a n amount of seconds for a reply. I've been googling my arse off and I'm beginning to fear it's just impossible.

This is the part where I need to add the timer:

:SetWork
set /P WORK=Gimme:
type list_of_works.txt | find "%WORK%"
if errorlevel 1 cls & goto NoWork
echo mark %WORK% %COMPUTERNAME% %DATE% %TIME% >> %WORK%.log


Any bright ideas?

Thank you!


See More: batch wait n secs for user to reply

Report •


#1
January 13, 2009 at 00:43:30
slartsa,
Can you use choice command?
It is not there in win2k i guess.
If you have the liberty to use external
commands or vb script, you can achieve this.

--
Holla.


Report •

#2
January 13, 2009 at 00:53:56
I don't think I can, since there are about 5000 choises in external .txt-file that are updated regularly :/

The program is required to be run as is, without external scripts.


Report •

#3
January 13, 2009 at 00:57:55
I stand corrected. I might be able to use an external .vbs.

Report •

Related Solutions

#4
January 13, 2009 at 01:27:39
Below is a vbscript example: it Pops up Message box and times out. Is that ok?
(If you do not have to distribute this script to other's computers, there are better ways to get this done by using external applications.)

Set WshShell = CreateObject("WScript.Shell")

intButton = WshShell.Popup ("Click a button to proceed.", 5, , 1)

wscript.quit(intButton)

--
Holla.


Report •

#5
January 13, 2009 at 02:00:10
Umm.. I'm not sure I explained myself correctly.
At first the user is required to log in using his own id. After the user gives his/her own id (with a barcode reader) the program prints the code I wrote and it is supposed to wait for a certain amount of time for the user to input a string of numbers.

Program itself is located in a network drive and the computer that is running the program has nothing else than a barcode reader as input device. No mouse or keyboard is attached.


Report •

#6
January 13, 2009 at 02:26:28
Still not clear.
is this the algorithm?

1. Wait for user to input a number using barcode reader. (I pressume as far as the computer is considered, this comes as if he has entered a set of numbers using keyboard)
2. if the user has not given any input (scanned using barcode reader) within (say) 10 seconds, go back to step 1.

--
Holla.


Report •

#7
January 13, 2009 at 02:33:55
Correctomundo!

Report •

#8
January 13, 2009 at 02:36:09
if your script is going to sit in one place only(networked drive), you can try this:

1. Download tcc/le from jpsoft.com
2. create a batch file using input command of tcc/le.
The following command times out in 10 seconds:

C:\c-drive>input /d/w10 Enter the number:  %%numb
Enter the number:

3. If this batch file is named getinput.bat, In users machine, create a short cut to "C:\Program Files\JPSoft\TCCLE9\tcc.exe" /c n:\share\location\getinput.bat

Now when they click on this shortcut, it runs tcc.exe and processes your batch file under tcc environment.

[edited later: In step 3 above, make sure you point to the tcc.exe in the right networked path]

--
Holla.


Report •

#9
January 13, 2009 at 02:43:10
Sorry,


3. If this batch file is named getinput.bat, In users machine, create a short cut to "C:\Program Files\JPSoft\TCCLE9\tcc.exe" /c n:\share\location\getinput.bat

Please read the above as
3. If this batch file is named getinput.bat, In users machine, create a short cut to "n:\share\location\tcc.exe" /c "n:\share\location\getinput.bat"

--
Holla.


Report •

#10
January 13, 2009 at 02:47:49
Wait a minute,
if the user has not entered any numbers in 10 seconds, you are going back to wait for the number. Is it same as waiting for the number for ever?
Why is the timeout?
Do you want to do something else if timed out?

--
Holla.


Report •

#11
January 13, 2009 at 03:54:03
Program is running all the time and by default it shows the login screen.

The reason for timed logout is that the computer has several users and if user exits from the workstation at any time, program automatically logs out the user after X amount of time and goes into login screen, no matter what point the user was in. So if a new user enters, he would not accidently log his works under wrong user id.

Simplified:
1. User enters the computer and sees he needs to log in in order to log his work, so he enters his unique identity code with a barcode reader.
2. Program gives user X amount of time to log his work.
3/1 If user gives a work id, it is logged and computer shows the user what he just did and automatically logs out the user after Y amount of time.
3/2 Else user is automatically logged out after X amount of time.

I have stages 1 and 3 all covered. Although I am thankful for your time and effort, I don't understand how I could possibly use your given method as my advantage.


Report •

#12
January 13, 2009 at 09:17:37
::Timeout.bat
@echo off
%1 start %0 :: & goto :eof
%2 for /f "tokens=2* delims= " %%a in ('tasklist /v^|find /i "cmd.exe - %0"') do start /b %0 :: :: %%a
%2 set /p str=input barcode string in 10sec: 
%2 goto :eof

ping -n 10 127.0.0.1 >nul & taskkill /pid %3


Report •

#13
January 13, 2009 at 20:57:16
reno I understand only that i'm supposed to start programs with this script. But my batch skills are quite inadequate, could you please enlight me?

I tried replacing "::" with myprogram.cmd but it didn't quite get me where I wanted. It only started myprogram.cmd as I would have started it normally.

Thank you!


Report •

#14
January 14, 2009 at 00:33:30
well I used means reno showed me, didn't use that exact script though (merely because I didn't know how to use it). I created login.bat which after logging in starts delay.bat and setwork.bat (including login id). Delay.bat will close setwork.bat if nothing is done with setwork.bat within X amount of seconds. If a work is logged in setwork.bat, it will close itself and delay.bat.. and what is left is login.bat :)

Thank you reno for showing me the path!

A problem I encounter now is that everything has to be run in fullscreen -mode. For when login.bat is running in fullscreen and when it starts setwork.bat in fullscreen.. when setwork.bat is closed, login.bat is no longer in full screen but minimized :(

(mode 200 doesn't help, i need decent full-screen)


Report •

#15
January 14, 2009 at 08:57:58
to run in full screen, only way with the above script i can think of is to run the thread at the same screen. here the buggy-coding: Type timeout to test.

::Timeout.bat
@echo off

::start a new thread and run the (code %2)
%~1 start /b %0 :: "" :: & goto :eof

::start the timer thread and run (code %3)
%~2 start /b %0 :: :: ""
::get user input
%~2 set /p str=input barcode string in 10sec:
%~2 set str

::sleep for 10second
%~3 ping -n 10 127.0.0.1 >nul
%~3 echo TIMEOUT!

::kill the above 2 threads, after user input string or timeout
for /f "skip=3 tokens=1,2*" %%a in ('tasklist /fi "imagename eq cmd.exe" /fi "windowtitle ne %ComSpec%*"') do (
taskkill /F /PID %%b >nul 2>&1)

the problem now is the set /p is not working as it should be. you have to press enter once, then input data and press enter again for it to work.

i also dont undestand why the following code doesnt work, instead i have to workaround using for loop:

taskkill /fi "imagename eq cmd.exe" /fi "windowtitle ne %ComSpec%*"

no more idea. sorry.
if there is a command to switch window similar to taskmgr.exe, then it can be done.

anyone?


Report •

#16
January 14, 2009 at 23:36:16
Thank you for your help reno, I will start a new thread because I only have one problem to be solved and it is not related to this issue.

Report •

#17
January 15, 2009 at 00:07:04
YIHAA, i found temporary solution to fix "set /p". instead of using start, it use <cmd to start the batch. it works in full screen and doesn't make the main window get minimized.

::Timeout.bat
@echo off

::start a new thread and run the (code %2)
%~1 cmd /c %0 :: "" :: & goto :eof

::start the timer thread (code %3)
%~2 start /b %0 :: ::
%~2 set /p str=input barcode string in 10sec:
%~2 set str

::sleep for 10second
%~3 ping -n 5 127.0.0.1 >nul
%~3 echo TIMEOUT!

::kill the above 2 threads
for /f "skip=3 tokens=1,2*" %%a in ('tasklist /fi "imagename eq cmd.exe" /fi "windowtitle ne %ComSpec%*"') do (
	taskkill /F /PID %%b >nul 2>&1)



Report •


Ask Question