Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!purdue!decwrl!manana.dec.com!birdsall From: birdsall@manana.dec.com Newsgroups: comp.sys.ibm.pc Subject: Interactive BAT files: here's how Message-ID: <8810040015.AA21729@decwrl.dec.com> Date: 4 Oct 88 00:15:55 GMT Organization: Digital Equipment Corporation Lines: 101 > Subject: Interactive BAT files: HOW? > Posted: 29 Sep 88 00:19:14 GMT > Organization: Evans & Sutherland, Salt Lake City, Utah > I would like to alter my AUTOEXEC.BAT file (or another BAT file) > to accept interactive input. I want it to ask me a question > (such as who I am), and based on the answer, perform a system setup. > Alas, I cannot find anything in my eMeSS-DOS (3.3) manual or elsewhere > that tells me how to do this. Is it possible? If so, how, and which > book(s) describe it? Is it "possible"? Why of course! All things are possible under MS-DOS ... but it can be painful ... Try this: First write a C program that asks you questions and returns some value based on your answer. if (strcmp (Input_Buffer, "one") == 0) return (1); Now write a BAT file. Include your C program at the top. It will return its value in ERRORLEVEL. Then write some BAT statements that branch on ERRORLEVEL (consult your DOS reference manual ). The syntax is a bit obscure but this is how you branch on a specific errorlevel using a BAT file IF statement: if errorlevel 1 if not errorlevel 2 goto one: if errorlevel 2 if not errorlevel 3 goto two: goto exit: :one one statements ... goto exit :two two statements ... goto exit :and_so_on ... :exit Here is a sample C and sample BAT file. Cut, compile, link, and then modify to suit your application. =============ASK.C (cut here) =========== /* * compile and link as ASK.EXE (done under MSC 5.0) */ #include char buffer[20]; main() { int status; cprintf("Please enter user name: "); /* get a name from the user */ scanf("%19s", buffer); status = 0; /* reset status to 0 */ if (strcmp (buffer, "tom") == 0) /* is it tom? */ status = 1; /* yes. return a 1 */ if (strcmp (buffer, "dick") == 0) /* is it dick? */ status = 2; /* yes. return a 2 */ if (strcmp (buffer, "harry") == 0) /* is it harry? */ status = 3; /* yes. return a 3 */ return(status); } ================================== Now load and run the following BAT file: ================== INQUIRE.BAT (cut here) =================== echo off ask if errorlevel 0 if not errorlevel 1 goto zilch: if errorlevel 1 if not errorlevel 2 goto tom: if errorlevel 2 if not errorlevel 3 goto dick: if errorlevel 3 if not errorlevel 4 goto harry: :tom echo Matched on tom goto exit :dick echo Matched on dick goto exit :harry echo Matched on harry goto exit :zilch echo No Name Was Matched :exit ==================================================== Have fun! walt