Correct syntax for CommandExecutionResult?

Advertisement

will.waterston@gmail.com
Joined:
Posts:
4
Location:
Brisbane, Australia

Correct syntax for CommandExecutionResult?

Hi,

What is the correct syntax for getting an instance of CommandExecutionResult?
I've tried -
string ceResult = session.ExecuteCommand("ls -al").Output;
and
CommandExecutionResult ceResult = session.ExecuteCommand("ls " + sft.destFile);
I've tried throwing in the new keyword as well, but all of these result in the exception -
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Thanks.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,603
Location:
Prague, Czechia

Re: Correct syntax for CommandExecutionResult?

The second syntax is correct (assuming the session is not null).

If you have problems, we need complete example.

Reply with quote

will.waterston@gmail.com
Joined:
Posts:
4
Location:
Brisbane, Australia

Thanks,

That syntax seems to be working now, the exception was actually being generated somewhere else.

Now I'm having trouble trying to capture the results of my ls command. ExecuteCommand() seems to generate an exception regardless of the success or failure of the command. I try to compare CommandExecutionResult.Output immediately after executing the command but that code is never executed because execution has jumped to the exception -
CommandExecutionResult ceResult = session.ExecuteCommand("ls /www");
if (ceResult.Output.ToUpper().Contains("NO SUCH FILE OR DIRECTORY"))
{
    session.CreateDirectory(sft.destFile);
}
I've got the help doco on how to capture results of operations, but I'm still unsure what to do. Do I need to create an instance of one of the OperationResultBase? If so, is there an example of how that is done following ExecuteCommand()?

Thanks.

Reply with quote

Advertisement

You can post new topics in this forum