EldoS | Feel safer!

Software components for data protection, secure storage and transfer

OnOpenShell

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#7611
Posted: 09/15/2008 08:41:19
by Ken Ivanov (EldoS Corp.)

Your modification is not correct, as you should create an instance of TElShellSSHSubsystemHandler class (not of TElCustomSSHSubsystemHandler). Please try to cast TElShellSSHSubsystemHandler to TElCustomSSHSubsystemHandler explicitly:

TElSSHSubsystemThread((TElCustomSSHSubsystemHandler)(new TElShellSSHSubsystemHandler(Connection, true)), Connection, true);
#7612
Posted: 09/15/2008 08:54:59
by Manfred Domandl (Basic support level)
Joined: 09/11/2008
Posts: 9

I changed as you have recommended.
Now I get this compile error:
"Fehler CS0246: Der Typ- oder Namespacename "TElShellSSHSubsystemHandler" konnte nicht gefunden werden. (Fehlt eine using-Direktive oder ein Assemblyverweis?)"

Is it possible to add an additional assambly?
#7615
Posted: 09/15/2008 10:52:34
by Ken Ivanov (EldoS Corp.)

Hmm, it's quite strange. We will try to reproduce the issue and get back to you as soon as possible.
#7617
Posted: 09/15/2008 12:07:49
by Ken Ivanov (EldoS Corp.)

Got it. TElShellSSHSubsystemHandler class has not been implemented for Compact Frameworks due to difficulties with redirecting process standard input and output streams.

You can implement TElShellSSHSubsystemHandler for CF yourself. In general, you should do the following:
a) create a descendant of TElCustomSSHSubsystemHandler and name it TElShellSSHSubsystemHandler,
b) override its HandlerType() method which will just return TSBSSHSubsystemHandlerType.shtSynchronous value,
c) override its Execute() method which will create the process with a needed name and run a read-write loop while the process is active. The code for desktop Framework follows:
Code
procedure TElShellSSHSubsystemHandler.Execute;
var
  Buf : ByteArray;
  ChBuf : CharArray;
  StdOutReader, StdErrReader: Thread;
  cmd: string;
  Received: cardinal;
  S: string;
  Changed : boolean;
begin
  SetLength(Buf, 8192);
  SetLength(ChBuf, 8192);
  if Length(Command) = 0 then
    cmd := GetEnvironmentVariable('COMSPEC')
  else
    cmd := GetEnvironmentVariable('COMSPEC') + ' /c ' + Command;
  FProc := Process.Create;
  FProc.StartInfo.Filename := cmd;
  FProc.StartInfo.RedirectStandardInput := true;
  FProc.StartInfo.RedirectStandardOutput := true;
  FProc.StartInfo.RedirectStandardError := true;
  FProc.StartInfo.UseShellExecute := false;
  FProc.StartInfo.WindowStyle := ProcessWindowStyle.Hidden;
  FProc.StartInfo.CreateNoWindow := true;
  FSync := TElSharedResource.Create;
  if FProc.Start() then
  begin
    try
      StdOutReader := Thread.Create(new ThreadStart(ProcessStdOutput));
      StdErrReader := Thread.Create(new ThreadStart(ProcessStdError));
      StdOutReader.Start();
      StdErrReader.Start();
      while
        (not FProc.HasExited)
        and (not Terminated) and (Connected) do
      begin
        Changed := false;
        Received := ReceiveData(Buf, 0, Length(Buf));
        S := ConvLF(Buf, 0, Received);
        if Length(S) > 0 then
        begin
          FProc.StandardInput.Write(S);
          Changed := true;
        end;
        FSync.WaitToWrite();
        try
          if Length(FStdOutSpool) > 0 then
          begin
            SendData(FStdOutSpool);
            SetLength(FStdOutSpool, 0);
            Changed := true;
          end;
          if Length(FStdErrSpool) > 0 then
          begin
            SendData(FStdErrSpool);
            SetLength(FStdErrSpool, 0);
            Changed := true;
          end;
        finally
          FSync.Done;
        end;
        if not Changed then
          Thread.Sleep(200)
        else
          Thread.Sleep(0);
      end;
    finally
      Cleanup;
    end;
  end;
end;
#7622
Posted: 09/16/2008 03:52:56
by Manfred Domandl (Basic support level)
Joined: 09/11/2008
Posts: 9

Thank you very much.
Now i will try to translate the provided Delphi code into C# code.
#7623
Posted: 09/16/2008 04:35:29
by Manfred Domandl (Basic support level)
Joined: 09/11/2008
Posts: 9

Ok, this will not work because this is although no Compact Framework (CF) code.
i.e: FProc.StartInfo.RedirectStandardInput does not exit in CF....
#7624
Posted: 09/16/2008 06:29:12
by Ken Ivanov (EldoS Corp.)

Yes -- those are the differences I have mentioned in the previous post.

Actually, there does exist an another way to implement input/output redirection -- by calling WinAPI process-related functions using P/Invoke.
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

Topic viewed 6231 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!