May 29, 2007

Answering CLI Prompts Programatically

Surround SCM
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).


Some 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 example

In 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
I get this prompt:
Are you sure you want to destroy this branch?
There is no undo available. [Y/N]:
If I run the rb command as a batch file, the question is not answered and the branch is not removed. To solve this problem with DOS commands, pipe the answer to the command. The general syntax is:
ECHO <answer>|<command>
In the rb command example, if I change the command in the batch file to look like this:
ECHO Y|sscm rb granny -pTest -ccMyComment -d -yAdministrator:password -z127.0.0.1:4900
The command runs, answers the question, and the 'granny' branch is destroyed (because I passed the -d option).

Other Examples

I work in a Windows environment and could not test if there is a similar option in non-Windows scripting languages, like a shell language for a Unix system. However, I am sure that other scripting languages include a way to pipe the answer to a prompt.


Piping the answer to a Surround SCM CLI command prompt allows users to automatically run commands in a script environment, without requiring user interaction. Note: Seapine does not provide support for sample triggers and scripts.