This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
cmd:prompt [2011/03/07 20:15] mcb30 created |
cmd:prompt [2012/03/28 23:32] mcb30 |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Prompt the user to press a key ====== | + | ====== Prompt user to press key ====== |
===== Synopsis ===== | ===== Synopsis ===== | ||
- | prompt [--key <keycode>] [--timeout <timeout>] [<text>] | + | prompt [--key <key>] [--timeout <timeout>] [<text>] |
===== Examples ===== | ===== Examples ===== | ||
Line 14: | Line 14: | ||
prompt Press any key to continue | prompt Press any key to continue | ||
+ | |||
+ | === Exit script if 'q' is pressed === | ||
+ | |||
+ | prompt --key q Press 'q' to quit && exit || | ||
=== Exit script unless F12 is pressed within 2 seconds === | === Exit script unless F12 is pressed within 2 seconds === | ||
Line 21: | Line 25: | ||
=== Offer user an opportunity to enter the iPXE shell === | === Offer user an opportunity to enter the iPXE shell === | ||
- | prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE shell... && shell || | + | prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE command line... && shell || |
===== Description ===== | ===== Description ===== | ||
Line 31: | Line 35: | ||
The displayed text will be cleared when the user presses a key, or if the timeout expires. | The displayed text will be cleared when the user presses a key, or if the timeout expires. | ||
- | The keycodes used for the ''--key'' option are extended ASCII character values. The values for special keys such as ''Ctrl-B'' and ''F12'' are defined in [[http://git.ipxe.org/ipxe.git/blob/HEAD:/src/include/ipxe/keys.h|include/ipxe/keys.h]] within the iPXE source code. Some useful values are: | + | The ''%%--key%%'' option can be specified as a character literal (such as ''q'' or ''@'') or as an extended ASCII character value. The values for special keys such as ''Ctrl-B'' and ''F12'' are defined in [[http://git.ipxe.org/ipxe.git/blob/HEAD:/src/include/ipxe/keys.h|include/ipxe/keys.h]] within the iPXE source code. Some useful values are: |
^ Key ^ Keycode | | ^ Key ^ Keycode | | ||
Line 60: | Line 64: | ||
===== Notes ===== | ===== Notes ===== | ||
+ | |||
+ | To prevent the ''prompt'' command from causing your script to exit, you will almost always want to use the ''||'' operator. For example, do **not** use a line such as | ||
+ | |||
+ | prompt --timeout 1000 Press any key to install Linux && goto install | ||
+ | |||
+ | If the user does not press a key, then the ''prompt'' command will fail and will cause your script to exit immediately. You can avoid this problem by using the ''||'' operator to ensure that the failure of the ''prompt'' command is handled appropriately. For example: | ||
+ | |||
+ | prompt --timeout 1000 Press any key to install Linux && goto install || goto no_install | ||
+ | |||
+ | or | ||
+ | |||
+ | prompt --timeout 1000 Press any key to install Linux && goto install || | ||
+ | |||
+ | See the iPXE [[:scripting|scripting]] guide for further information on the ''&&'' and ''||'' operators. | ||
+ | |||
+ | When you use an embedded script, you will no longer see the "Press Ctrl-B for the iPXE command line" prompt at startup or if booting fails. You can generate your own prompt using the ''prompt'' command. For example: | ||
+ | |||
+ | #!ipxe | ||
+ | | ||
+ | # Give user a chance to enter the shell | ||
+ | prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE shell... || goto no_shell | ||
+ | shell | ||
+ | exit | ||
+ | | ||
+ | :no_shell | ||
+ | # Boot the system | ||
+ | ... | ||