0

Given:

var linuxCommmand = "/opt/ndmcli -x"; 
var linuxOptions = "sel stat pnum=157 detail=yes;\nquit;"; 
SSH.ExecuteCommand(String.Format("{0} <<!!\r\n{1}\r\n!!\r\n", linuxCommand, linuxOptions)); 

Consulting the session log shows the command is correct, with this:

2016-10-25 14:12:49.433 Script: call /opt/cdunix/ndm/bin/ndmcli -x <<!!
2016-10-25 14:12:49.433 sel stat pnum=157 detail=yes;
2016-10-25 14:12:49.433 quit;
2016-10-25 14:12:49.433 !!
2016-10-25 14:12:49.433 Executing user defined command.
2016-10-25 14:12:49.433 /opt/cdunix/ndm/bin/ndmcli -x <<!!
2016-10-25 14:12:49.433 sel stat pnum=157 detail=yes;
2016-10-25 14:12:49.433 quit;
2016-10-25 14:12:49.433 !! ; echo "WinSCP: this is end-of-file:$?"
2016-10-25 14:13:04.437 Waiting for data timed out, asking user what to do.
2016-10-25 14:13:04.437 Asking user:
2016-10-25 14:13:04.437 **Host is not communicating for 15 seconds.
2016-10-25 14:13:04.437 
2016-10-25 14:13:04.437 Wait for another 15 seconds?** ()

Is there any reason I couldn't use stdin redirection with WinSCPNet's ExecuteCommand?

Thanks!

****UPDATE**** Weirdly, if I add a trailing space:

var linuxCommmand = "/opt/ndmcli -x"; 
var linuxOptions = "sel stat pnum=157 detail=yes;\nquit;"; 
SSH.ExecuteCommand(String.Format("{0} <<!!\r\n{1}\r\n!!\r\n ", linuxCommand, linuxOptions)); 

It all works fine:

2016-10-25 15:58:03.489 Script: call /opt/cdunix/ndm/bin/ndmcli -x <<!!

2016-10-25 15:58:03.489 sel stat pnum=157 detail=yes;
2016-10-25 15:58:03.489 quit;

2016-10-25 15:58:03.489 !!

2016-10-25 15:58:03.489  
2016-10-25 15:58:03.489 Executing user defined command.
2016-10-25 15:58:03.489 /opt/cdunix/ndm/bin/ndmcli -x <<!!

2016-10-25 15:58:03.489 sel stat pnum=157 detail=yes;
2016-10-25 15:58:03.489 quit;

2016-10-25 15:58:03.489 !!

2016-10-25 15:58:03.489   ; echo "WinSCP: this is end-of-file:$?"
2016-10-25 15:58:03.550 Script: 
2016-10-25 15:58:03.550 Script:     **************************************************************
2016-10-25 15:58:03.550     **************************************************************
2016-10-25 15:58:03.550 Script:     *                                                            *
2016-10-25 15:58:03.550     *                                                            *
2016-10-25 15:58:03.550 Script:     *            Licensed Materials - Property of IBM            *
---- (log continues, and I get my expected output) ----
John
  • 921
  • 1
  • 9
  • 24

1 Answers1

0

The new-lines will completely confuse WinSCP.

The command is actually not executed correctly, as the trailing !! has to be alone on a line, what it is not.


You have to put everything on a single line.

This can work:

( echo sel stat pnum=157 detail=yes; & echo quit; ) | /opt/cdunix/ndm/bin/ndmcli -x 
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • The echo via pipe didn't work - which makes sense, lol. ndmcli is a standalone executable that then expects the input of sel stat pnum=157 detail=yes; quit;, and then outputs the necessary information. – John Oct 25 '16 at 19:40
  • the command should have the final !! on its own line, as the \r\n is both before and after the final !!. Does WinSCP do some sort of parsing of the command prior to sending it? – John Oct 25 '16 at 19:42
  • No it does not make sense, why it should not work? The `echo` produces the ouput that your command expects on input. – Martin Prikryl Oct 25 '16 at 19:50
  • Not sure. Reset back to what's in the original question, simply added a trailing space, and now it's working as expected. Odd! – John Oct 25 '16 at 19:53