Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Executing a Command Synchronously

Executing a Command Synchronously

A command is a single task that you want to execute on every node in the cluster. The command is not scheduled like a job but is executed immediately. The task must contain the command line to execute. To limit the nodes on which the command runs, call the ITask::put_RequiredNodes method. You may also set the following task properties (other task properties are ignored if set):

To execute the command, call either the ICluster::ExecuteCommand or ICluster::ExecuteCommandWithPaging method. If you expect the command to generate a large volume of output and you want to be able to page through the output, consider using ExecuteCommandWithPaging.

The ExecuteCommand method waits until the results from all nodes are returned.

The following example shows how to execute a command synchronously.


ITask task;
IClusterEnumerable executionResults;

task = cluster.CreateTask();
task.CommandLine = @"dir %windir%\system32\setup";

try
{
    executionResults = cluster.ExecuteCommandWithPaging(cluster.GetNewCommandId(),
        task,
        null,
        null,
        true,
        0,
        2048);

        Console.WriteLine("\nCommand: " + task.CommandLine);

        foreach (IExecutionResult result in executionResults)
        {
            string output;

            Console.WriteLine("\nOutput from " + result.NodeName + "\n");
            while ((output = cluster.ReadExecutionResult(result)) != string.Empty)
            {
                Console.Write(output);
            }
        }
}
catch (Exception e)
{
    Console.WriteLine("\nExecuteCommandWithPaging failed.\n" + e.Message);
}

Related topics

Using CCP

 

 

Show:
© 2015 Microsoft