May 29, 2007
Answering CLI Prompts Programatically
Some of the Surround SCM CLI commands prompt the user with an "are you sure [Y/N]:?" question. This presents a problem for users who want to automatically run these commands in a script environment and the commands should not need user interaction (i.e., a user click the "Y" or "N" key when prompted).
SolutionsSome commands offer a way to not prompt the user. For example, the rm command has a -q option, and when used, it does not prompt the user. However, other commands that do not have this option. Until the option to not prompt the user is added to these commands, the user will have to resort to the scripting language used to automatically answer this question.
DOS exampleIn DOS, you can pipe the answer into the command that you run. For example, I want to delete a branch and do not want to be prompted. If I run the following command:
- sscm rb granny -pTest -ccMyComment -d -yAdministrator:password -z127.0.0.1:4900
- Are you sure you want to destroy this branch?
- There is no undo available. [Y/N]:
- ECHO <answer>|<command>
- ECHO Y|sscm rb granny -pTest -ccMyComment -d -yAdministrator:password -z127.0.0.1:4900