ExecuteCommand issues

Advertisement

Austen
Joined:
Posts:
1

ExecuteCommand issues

Hi,

We need to be able to execute various commands prior to retrieving sets of files from the server, and we are having some issues doing this with the RC of WinSCP.

First, we tried executing the command and waiting for the returned result e.g.

CommandExecutionResult result = session.ExecuteCommand("ps -ef | egrep \"srp\" | grep -v grep");

This works fine for simple commands, but failed for the example given above, returning immediately with:

Exception:WinSCP.SessionRemoteException: Missing parameter for command 'call'.
at WinSCP.SessionLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags)
at WinSCP.CustomLogReader.WaitForNonEmptyElement(String localName, LogReadFlags flags)
at WinSCP.Session.ExecuteCommand(String command)

We then tried hooking the OutputDataReceived and Failed events, which was a lot more successful in that the same command executed without exception and we got some data back. However, we are expecting multiline results, and the OutputDataReceived event is firing on each line received, with no obvious marker as to when the command output has been received in full.

So, my questions are these:

1) Any idea why the command does not work when waiting for the results of Session.ExecuteCommand, as in the first example?
2) When hooking the events, is there any way of telling when we have hit the end of the output for a command?

Thanks for the help, and what is shaping up to be a great product!

Austen

Reply with quote

Advertisement

hcreel
Joined:
Posts:
1
Location:
Tampa, FL

ExecuteCommand returns nothing for non-zero exits

If I try to execute a script that displays several messages, and then exits with a non-zero number, the CommandExecutionResult is never set because of the exception that is generated. So I cannot see any of the messages. How about adding a ReturnCode to the CommandExecutionResult and not generating an exception?

Reply with quote

martin
Site Admin
martin avatar

Re: ExecuteCommand returns nothing for non-zero exits

Will consider that. Meanwhile you can append noop command after the failing command to suppress the error exit code.
I.e.
session.ExecuteCommand("<your failing command> ; :");

Reply with quote

Advertisement

You can post new topics in this forum