[comp.os.msdos.programmer] Autoexec.bat prob: take two

Thomson_PW@cc.curtin.edu.au (10/10/90)

I have set up my computer to load straight up into Windows 3
from my autoexec.bat file. However somtimes I just want to load
xtree to do some copying/moving. 

I saw once a programme which was called from the autoexec.bat file 
which loaded for a few seconds then finished and let the batch file
continue on. This was to give the user time enough to do a <ctrl> c
to stop the batch file.

Has anyone seen a programme similar to this ?

thanks in advance.

Tommy.

kdq@demott.COM (Kevin D. Quitt) (10/10/90)

In article <3936.27135c52@cc.curtin.edu.au> Thomson_PW@cc.curtin.edu.au writes:
>I saw once a programme which was called from the autoexec.bat file 
>which loaded for a few seconds then finished and let the batch file
>continue on. This was to give the user time enough to do a <ctrl> c
>to stop the batch file.

    I have a program called getyesno which will accept a prompt and a
timeout on its command line, then wait the specified amount of time for
a y/n response.  The result is in the errorlevel variable.  Aw, heck with it,
it's under 2K.

               O /
----------------X---------------- Cut Here
               O \
/*  GETYESNO.C  30-Nov-87   Kevin D. Quitt

    Gets a Yes or No answer from the operator, with a command-line
    specified time-out. A timeout of zero waits forever. If yes is entered,
    errorlevel is 1, no yields 0, a timeout yields 2.

13-Jul-88 10:48:10, [VTEK]c:\utils\source\getyesno.c, Edit 880713104810 by KDQ
    Added one-time output of string parameters past the timeout value.
*/

#include    "disk.h"
#include    <stdio.h>
#include    <conio.h>
#include    <time.h>

#define TRUE    (1==1)
#define FALSE   (1!=1)

int main( int argc, char *argv[] )
   {
    int      c, secs = 0, gotanswer = FALSE, response;
    long     elapsed = -1L, stime;

    if ( argv[1][0] == '?' )
       {
        printf( "Format is:\ngetyesno [optional maximum wait]\n" );
        return -1;
       }

    if  ( --argc  >  0 )
        sscanf( argv[1], "%d", &secs );

    c   = 2;
    while ( argv[ c ] )                 /* Print the extra text             */
        printf( "%s ", argv[ c++ ] );

    while (!gotanswer)
       {
        gotanswer   = TRUE;
        response    = 'y';              /* and the answer is yes    */

        if ( secs == 0 )
            response    = getche();
        else
           {
            stime   = time( NULL );
            elapsed = 0;
            while ( elapsed < secs )
               {
                if (kbhit())
                   {
                    response    = getche();
                    break;
                   }
                else
                   {
                    if ( stime != time(NULL) )
                       {
                        elapsed++;
                        stime       = time(NULL);
                       }
                   }
               }
           }

        response |= ( 'a' ^ 'A' );      /* Fold down    */

        if ( (response != 'y') && (response != 'n' ) )
           {
            gotanswer   = FALSE;
            printf( "\nPlease answer Yes or No: " );
           }
       }

    printf ("\n" );

    if ( elapsed >= secs )  return  2;
    if ( response == 'y' )  return  1;
    else                    return  0;

   }
               O /
----------------X---------------- Cut Here
               O \

    It's not great, but I wrote it in a previous life, and it's free.
-- 
 _
Kevin D. Quitt         demott!kdq   kdq@demott.com
DeMott Electronics Co. 14707 Keswick St.   Van Nuys, CA 91405-1266
VOICE (818) 988-4975   FAX (818) 997-1190  MODEM (818) 997-4496 PEP last

                96.37% of all statistics are made up.

tcs@router.jhuapl.edu (10/10/90)

In article <3936.27135c52@cc.curtin.edu.au>, Thomson_PW@cc.curtin.edu.au writes:
>I have set up my computer to load straight up into Windows 3
>from my autoexec.bat file. However somtimes I just want to load
>xtree to do some copying/moving. 
>
>I saw once a programme which was called from the autoexec.bat file 
>which loaded for a few seconds then finished and let the batch file
>continue on. This was to give the user time enough to do a <ctrl> c
>to stop the batch file.
>
>Has anyone seen a programme similar to this ?
>
>thanks in advance.
>
>Tommy.

I have a program here called TAsk from SEA, I think. I'm sure someone else 
will have an FTP'able one for you, but I will UUENCODE and mail it in a few 
minutes...


Carl Schelin
tcs@router.jhuapl.edu

lsalomo@sleepy.uucp (Lawrence W Salomon) (10/11/90)

Why make is so specific?  A better solution, IMHO, is the following:

/* ---------- Cut here ---------- */
#include <stdio.h>
#include <string.h>

main(argc,argv)
   int argc;
   char *argv[];
{
   char input;

   if (argc>2) {
      puts("Syntax:  ONECHAR [verify]");
      putchar('\n');
      puts("verify - an optional string of valid input characters.");
      puts("         If omitted, any character is considered valid.");
      puts("         The characters are case-insensitive.");
      putchar('\n');
      puts("ONECHAR returns the character pressed as the return code.");
      exit(2);
   } else 
   if (argc==2) {
      strupr(argv[1]);
   } /* endif */

   do {
      input=getchar();
      if ((argc==2) && (strchr(argv[1],input)!=NULL)) {
         argc==1;
      } /* endif */
   } while (argc!=1);

   return input;
}

/* ---------- End of cut -------- */

(Hmm...That looks correct, but of course I typed it in on the fly and so it
hasn't been compiled/tested/etc.)  As the help text indicates, ONECHAR 
accepts an optional string which is a list of valid characters.  The character
pressed is returned as the return code, which can be tested by ERRORLEVEL
in a batch file.

Have fun...(Please let me know if I made any mistakes)...

Cheers,
Q

mitchell (Bill Mitchell) (10/11/90)

In article <744@demott.COM> kdq@demott.COM (Kevin D. Quitt) writes:
>In article <3936.27135c52@cc.curtin.edu.au> Thomson_PW@cc.curtin.edu.au writes:
>>I saw once a programme which was called from the autoexec.bat file 
>>which loaded for a few seconds then finished and let the batch file
>>continue on. This was to give the user time enough to do a <ctrl> c
>>to stop the batch file.
>

I missed the original posting, but how about the following quick&dirty:

break on
echo type CTRL-BREAK now to abort
dir a: >nul

harry@aeshq.UUCP (Harry Pulley) (10/12/90)

Why don't you place a PAUSE command in your AUTOEXEC.BAT at the point where you
wish to continue or abort the batch file.  The PAUSE command will ask the user
to "Hit any key to continue..." or something similar.  If the user then hits 
<CTRL-Break>, they will be asked "Terminate batch job? (Y/N)" or something of
that nature.  If the user then types "y", the batch file will stop, and they
will be in DOS.  With a keyboard that has a buffer, you could strike a key
before the file executes if you know that you want it to run to completion 
without waiting for the prompt.


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~     HCPIV (2b||!2b)     ~        Harry Pulley        ~   harry@aeshq.UUCP   ~ 
~    Computo, ergo sum    ~     Environment Canada     ~     TOR, ON, CA      ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

prs@io.UUCP (Paul Schmidt) (10/12/90)

In article <3936.27135c52@cc.curtin.edu.au> Thomson_PW@cc.curtin.edu.au writes:
> (deleted stuff on how to pause a batch file)
>
>Has anyone seen a programme similar to this ?

Yeah. It's called 'PAUSE', and is part of the DOS Batch File Command language.

RTFM

rusbara2@sage.cc.purdue.edu (Bob Rusbasan) (10/14/90)

In article <783@aeshq.UUCP> harry@aeshq.UUCP (Harry Pulley) writes:
>Why don't you place a PAUSE command in your AUTOEXEC.BAT at the point where you
>wish to continue or abort the batch file.  The PAUSE command will ask the user
>to "Hit any key to continue..." or something similar.  If the user then hits 
><CTRL-Break>, they will be asked "Terminate batch job? (Y/N)" or something of
>that nature.  If the user then types "y", the batch file will stop, and they
>will be in DOS. 

Or, for a very slight improvement, use "pause Press any key to load TSRs or
control-C otherwise" or something like that.  Whatever you put after
pause is echoed before the "Hit any key..." message, so that will clarify
what you're actually doing.


Bob Rusbasan
bob@en.ecn.purdue.edu

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (10/14/90)

I think the original question on this thread was how to put a pause in an
autoexec.bat file, in order to allow the user to abort Windows before it got
loaded.  A different approach, which I think is better, is as follows.

Maintain several directories of autoexec.bat/config.sys pairs, with names
evocative of what they intend to do.  For example, the original poster might
have a c:\BOOT\WINDOWS directory and a c:\BOOT\PLAIN directory.  Then, write a 
small batch file BOOT.BAT something like this:

  copy c:\boot\%1\*.* c:\
  warmboot

where "warmboot" is one of those tiny .COM utilities to do a warm boot.

Now, anytime you want to boot without Windows, you just type

  BOOT PLAIN

and you will!

A nice side effect of this approach is that it protects your configuration files
from rude installation programs that try to change them.  A nasty side effect
is that it's easy to make a change to the files in the root, and lose it a few
days later when you run BOOT.BAT.

Duncan Murdoch
dmurdoch@watstat.waterloo.edu

P.S.  A nice enhancement that can't easily be added without programming is to
have it save your current directory before it reboots, and have your AUTOEXEC
change to that directory as its last action.  That way it's a little less 
irritating to work on projects that need a couple of different configurations
at different times.  I do this to load the TD386 debugger which is incompatible
with my usual environment in Desqview.

richard@iesd.auc.dk (Richard Flamsholt S0rensen) (10/18/90)

In article <1990Oct14.030040.715@maytag.waterloo.edu> dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:
>Now, anytime you want to boot without Windows, you just type
>
>  BOOT PLAIN
>
>and you will!

  Gosh - anytime I want to boot without Windows? You mean, like, when
I'm staring at my PC with its big, red button in "OFF"-position, I
just type "boot plain" and turn on my computer  ;-)

  Seriously, though, even if it seems like an overkill I'll suggest
using 4DOS. Amongst its many pros, it has an INKEY function which when
giwen the argument /wxxx waits xxx seconds for the user to enter
something. In that way, you don't have to press anything to boot
normally, which would otherwise be a real nuisance (the pause command
requires you to type in something).




--
/Richard Flamsholt
richard@iesd.auc.dk