I have been scouring the web for a way to implement something like JoptionPain in Java. I have a command prompt program I have setup that I want to prompt the user to respond to whether they want to proceed or cancel, killing the window. I don't care whether it asks the user in cmd.exe or in a seperate window that pops up. How do I make cmd.exe interactive with the user running the command script?
Thanks a bunch, I have been looking for documentation on how to script an interactive prompt for user for sometime in little chunks but couldn't find an resource that talked about coding in cmd. Just out of curiousity where did you pick that up and is there any way to hide the inital coding in the prompt so it doesn't show up in the prompt before the question is asked?
I picked it up from looking at other batchfiles. Check out "cmd /?", there's a lot of starting points there. In particular, there's a list of native commands (including "for", "if", and other programming things) that all support usage info via a "/?" switch. Bring your patience hat. Google also returns some decent batch tutorials.
"off" is a special argument to echo to tell all the subsequent commands to not print before executing. "setlocal" is a scoping thing, the details are kinda complicated but it's a good habit to get into if you're planning on doing more complicated batchfiles, especially if you're calling into other batchfiles. For your purposes, it is only applying the "echo off" to your batchfile (among other things, but read the usage for those details).
Posts
set /p answer=Is cmd.exe the most poorly documented shell ever?
if /i "%answer%" == "y" (
echo That is correct!
) else (
echo WRONG!
)
Two ways:
You can hide any line in a batchfile by having "@" be the first non-whitespace character:
echo This will look funny
@echo This will look cleaner
The second is to put 2 lines at the top:
@setlocal
@echo off
"off" is a special argument to echo to tell all the subsequent commands to not print before executing. "setlocal" is a scoping thing, the details are kinda complicated but it's a good habit to get into if you're planning on doing more complicated batchfiles, especially if you're calling into other batchfiles. For your purposes, it is only applying the "echo off" to your batchfile (among other things, but read the usage for those details).