1

The original Unix implementation simply did something like this:

ssh [batchname] < [inputfilename] > [outputfilename]

I need to be able to do the same thing from a windows machine running an application written in C#. I've tried using SharpSsh, which includes input and output streams, but they don't seem to work.

How can I pipe the input and output files/streams using SharpSsh (or any other .Net library)?

Foozinator
  • 400
  • 3
  • 11
  • "It doesn't work" is too broad. Did you try to debug the code? What problems did you have? – Eugene Mayevski 'Callback Jan 19 '11 at 05:39
  • It depends on what I tried to do. In general, the behavior was like the streams never connected with the server. I don't know if the input stream ever got information to the server, but the output stream was always either closed and unreadable or a read would hang for far longer than it should have (should take a second or two, waited for minutes). – Foozinator Jan 19 '11 at 17:35
  • To be more explicit, if I use SshExec.RunCommand and simply add the input file contents to the command string (separating with a space or a newline), the RunCommand call doesn't return. If I use SshShell and write out the command and input file, the output stream is not available or remains empty. – Foozinator Jan 19 '11 at 20:11
  • Can you please post a code snippet how you figured it out? I am facing the same issue actually :( Need your help. Thanks in advance. –  Jun 07 '11 at 08:46

1 Answers1

1

Figured it out. Either the application running or SSH itself expects a ctrl-d to signal the end of the input. At that point, the output stream can be read without hanging.

Foozinator
  • 400
  • 3
  • 11