This project is read-only.

UNIX command issue

Nov 8, 2010 at 1:35 PM

Hi,

With the method Execute(string command) I try to execute the following command on a UNIX machine: ksh -c '[ -d $HOME/TestFolder.toremove ] && rm -fr $HOME/TestFolder.toremove'

It always raised an exception : "Object reference not set to an instance of an object."

Thanks

 

 

Coordinator
Nov 8, 2010 at 2:00 PM

Hi,

 

I cannot execute this command on my machine to test it but can you execute it while using source and let me know what line and where it throws this error?

Also, 

What is expected output when you run it on your machine?

 

Thanks,

Oleg

Nov 8, 2010 at 3:10 PM

Hi,

I was able to catch this exeception in the method MessageListener() line 952

  at Renci.SshClient.Channels.Channel.OnChannelClose()
   at Renci.SshClient.Channels.ChannelExec.OnChannelClose()
   at Renci.SshClient.Channels.Channel.HandleMessage(ChannelCloseMessage message)
   at CallSite.Target(Closure , CallSite , Channel , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at CallSite.Target(Closure , CallSite , Channel , Object )
   at Renci.SshClient.Channels.Channel.HandleChannelMessage(ChannelMessage message)
   at Renci.SshClient.Session.HandleMessage(ChannelMessage message)
   at Renci.SshClient.Session.HandleMessage[T](T message)
   at CallSite.Target(Closure , CallSite , Session , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at CallSite.Target(Closure , CallSite , Session , Object )
   at Renci.SshClient.Session.MessageListener()

I can try to drill down more but as I don't know/understand all the calls it will be diffcult.

 

 

Nov 8, 2010 at 3:16 PM

About your second question, there is no expected output after the command execution.

Coordinator
Nov 8, 2010 at 4:01 PM

Do you mind to download latest codeset and try it again? I did some changes which I think could resolve this problem.

When you catch the excpetion, if it happens again, can you run exp.ToString() command and send me its output, it will tell me which method was executed and at what line so I could trace execution path.

 

Thanks,

Oleg

Nov 8, 2010 at 4:43 PM

I've tried the latest source (4290) and I have a new error which happens before:

During the if (!this._socket.Connected) I have a: Object reference not set to an instance of an object.

Here's the stacktrace:

   at Renci.SshClient.Session.SendMessage(Message message) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Session.cs:line 516
   at Renci.SshClient.Channels.Channel.SendMessage(Message message) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\Channel.cs:line 167
   at Renci.SshClient.Channels.ChannelSession.SendChannelOpenMessage() in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSession.cs:line 163
   at Renci.SshClient.Channels.ChannelSession.Open() in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSession.cs:line 49
   at Renci.SshClient.Channels.ChannelSessionExec.BeginExecute(String command, Stream output, Stream extendedOutput, AsyncCallback callback, Object state) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSessionExec.cs:line 51
   at Renci.SshClient.Shell.BeginExecute(String command, Stream output, Stream extendedOutput, AsyncCallback callback, Object state) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 46
   at Renci.SshClient.Shell.Execute(String command, Stream output, Stream extended) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 34
   at Renci.SshClient.Shell.Execute(String command, Stream extended) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 26
   at Renci.SshClient.Shell.Execute(String command) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 19
   at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\ConsoleApplication1\Program.cs:line 15
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Coordinator
Nov 8, 2010 at 5:50 PM
did u issue a connect command prior to execute? if not that's probably what it is, I think I need to provide with better error message in this case

Sent from my iPhone

On Nov 8, 2010, at 11:53, Peuj <notifications@codeplex.com> wrote:

From: Peuj

I've tried the latest source (4290) and I have a new error which happens before:

During the if (!this._socket.Connected) I have a: Object reference not set to an instance of an object.

Here's the stacktrace:

at Renci.SshClient.Session.SendMessage(Message message) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Session.cs:line 516
at Renci.SshClient.Channels.Channel.SendMessage(Message message) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\Channel.cs:line 167
at Renci.SshClient.Channels.ChannelSession.SendChannelOpenMessage() in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSession.cs:line 163
at Renci.SshClient.Channels.ChannelSession.Open() in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSession.cs:line 49
at Renci.SshClient.Channels.ChannelSessionExec.BeginExecute(String command, Stream output, Stream extendedOutput, AsyncCallback callback, Object state) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSessionExec.cs:line 51
at Renci.SshClient.Shell.BeginExecute(String command, Stream output, Stream extendedOutput, AsyncCallback callback, Object state) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 46
at Renci.SshClient.Shell.Execute(String command, Stream output, Stream extended) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 34
at Renci.SshClient.Shell.Execute(String command, Stream extended) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 26
at Renci.SshClient.Shell.Execute(String command) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 19
at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\ConsoleApplication1\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Read the full discussion online.

To add a post to this discussion, reply to this email (sshnet@discussions.codeplex.com)

To start a new discussion for this project, email sshnet@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Nov 8, 2010 at 7:34 PM

I've just used the command

SshClient client = SshClient(ConnectionData.Host, ConnectionData.Username, ConnectionData.Password);

string output  = client.Shell.Execute("ls");

I'll try to debug tomorrow morning.

Nov 9, 2010 at 10:04 AM

Ok so the behavior has changed and that's why I did not connect to the computer (previous error).

Now about the error raised during the command execution, it also happens with the latest codeset.

The error is raised by the method Renci.SshClient.Session.WaitHandle(WaitHandle waitHandle)

Here's the error raised :

System.NullReferenceException: Object reference not set to an instance of an object.
   at Renci.SshClient.Session.WaitHandle(WaitHandle waitHandle) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Session.cs:line 495
   at Renci.SshClient.Channels.Channel.WaitHandle(WaitHandle waitHandle) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\Channel.cs:line 205
   at Renci.SshClient.Channels.ChannelSessionExec.EndExecute(IAsyncResult result) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSessionExec.cs:line 75
   at Renci.SshClient.Shell.EndExecute(IAsyncResult asynchResult) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 53
   at Renci.SshClient.Shell.Execute(String command, Stream output, Stream extended) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 34
   at Renci.SshClient.Shell.Execute(String command, Stream extended) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 26
   at Renci.SshClient.Shell.Execute(String command) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Shell.cs:line 19
   at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\ConsoleApplication1\Program.cs:line 19
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

 

 

 

 

Coordinator
Nov 9, 2010 at 2:16 PM

Peuj,

It looks like I would need to refactor my error handling so I could see a better picture of what happens, in this case what happened is the error was thrown by another thread and at this point it doesnt tell me an accurate picture.

Do you mind may be contact me on MSN olegkap1@hotmail.com or some other messaging software so we could resolve this issue faster?

Also, since you using the code version, do you mind to put a breakpoint in Session.cs file at line 1066 and 1076, this is where the original exception is thrown and print out exp.ToString()?

Thanks,

Oleg

Nov 9, 2010 at 3:07 PM

Oleg,

Here's the exp.ToString() result from line 1076:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Renci.SshClient.Channels.ChannelSession.OnClose() in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSession.cs:line 74
   at Renci.SshClient.Channels.ChannelSessionExec.OnClose() in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\ChannelSessionExec.cs:line 98
   at Renci.SshClient.Channels.Channel.OnChannelClose(Object sender, MessageEventArgs`1 e) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Channels\Channel.cs:line 270
   at Renci.SshClient.Session.HandleMessage(ChannelCloseMessage message) in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Session.cs:line 820
   at CallSite.Target(Closure , CallSite , Session , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at CallSite.Target(Closure , CallSite , Session , Object )
   at Renci.SshClient.Session.MessageListener() in C:\Users\Peuj\Downloads\sshnet-4290\Renci.SshClient\Renci.SshClient\Session.cs:line 1047

 

I've sent you a message on olegkap1@hotmail.com.

Coordinator
Nov 10, 2010 at 5:57 PM

Peuj,

 

I checked the new code today which have a SshCommand there, please refer to test cases for how to use this and let me know what you think.

 

Thanks,

Oleg

Nov 10, 2010 at 8:05 PM

Oleg,

Great !! I'll be busy this week so I should be able to give you a feedbacck on Monday.

Thanks