fieldrndservices / libssh2-labview

A LabVIEW library for SSH client support via libssh2
Apache License 2.0
22 stars 2 forks source link

SSH : two CMD in same channel #5

Closed Clio75 closed 4 years ago

Clio75 commented 4 years ago

Hi, I tried to send more that one CMD into the Channel I had created. image

But It return: Field_RnD_Services_LIBSSH2_Toolkit.lvlib:Check Status.vi [Bad Use Error] image

Do I need to wait or do something between CMD ?

volks73 commented 4 years ago

I think the Execute VI, and its underlying libssh2 function (libssh2_channel_exec) is an "execute once and get out" kind of function. In other words, it can only be used once per session/channel. See Execute multiple commands sequentially with libssh2 on StackOverflow, as it is identical to your error but for C instead of LabVIEW. There is unfortunately no answer or resolution, but it provides evidence that the you cannot use the Execute VI twice on the same session/channel.

Discussion on the libssh2 mailing list also indicates the channel must be destroyed/closed before another Execute can be used.

So, I think you have a couple of options: (1) Create/Open and Destroy/Close a channel for each Execute or (2) investigate using the Shell VI, with the Write All VI.

Option 2 actually looks like the appropriate implementation based on the ssh2.c example, but I have never really used the Shell VI. Here is a totally untested and probably does not work example:

Send Multiple Commands Example v1

Clio75 commented 4 years ago

I will investigate to use the shell option. I will let you know the result

volks73 commented 4 years ago

@Clio75, FYI, I created a new release (Alpha-2.0) that includes an example for the single command execution and the fixes for the palettes. If you get a working example of the Shell option, I will add it to the Examples and include in the next release.

Clio75 commented 4 years ago

With the VIP-1-0-0-15 pallet I have tested this: One channel for each CMD: image And it executing perfect.

But also this works; One channel for BOTH CMD: image

volks73 commented 4 years ago

Great! I will create some examples based on these screenshots and include them in the next release. I will probably not include them as usage examples in the README as those are meant to be quick, simple examples of doing one thing. These feel a little more complex, or something to look at after trying one of the usage examples.

I think this means this issue is resolved.