Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Go Back  Xtreme Visual Basic Talk > > > Streadreader and Plink.exe issues in VB.NET


Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2011, 11:53 AM
vb2008 vb2008 is offline
Regular
 
Join Date: Jan 2008
Posts: 88
Default Streadreader and Plink.exe issues in VB.NET


I am having issues with plink.exe and streamreader in vb.net. Everything seems to work fine except for the fact that the cmd window never closes and these logic seems to get stuck till I close the cmd window myself then it continues. I have an exit in here but it does not seem to do the trick. A cmd window will open with the white blinking cursor and it just sits till I press the X on the cmd window.

Code:
Private Sub NDS_Start_SIT_Click(sender As System.Object, e As System.EventArgs) Handles NDS_Start_SIT.Click
Dim CMDThread As New Threading.Thread(AddressOf NDS_Start_SIT_Logic)
CMDThread.Start()
End Sub

Private NDS_START_SIT_Status As New delUpdate(AddressOf NDS_Start_SIT_Logic)

Private Sub NDS_Start_SIT_Status_Capture()
Status_Capture_Box.Text = Results
End Sub

Private Sub NDS_Start_SIT_Logic()
Dim NDS_Start_SIT_Putty_Command_Value As String = "C:\plink.exe " + Unix_User_Name + "@spongeshrimp.grhq.XXX.com -pw " + Unix_User_Password
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo()
StartInfo.FileName = "cmd"
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False
StartInfo.CreateNoWindow = False 
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
SW.WriteLine(NDS_Start_SIT_Putty_Command_Value)
SW.WriteLine("ps -ef | grep nds")
SW.WriteLine("exit")
Results = SR.ReadToEnd
SW.Close()
SR.Close()
Invoke(NDS_Start_SIT_Updater)
End Sub
Any ideas? Thanks.
Reply With Quote
  #2  
Old 09-28-2011, 08:57 AM
vb2008 vb2008 is offline
Regular
 
Join Date: Jan 2008
Posts: 88
Default

Anyone? :-(
Reply With Quote
  #3  
Old 09-28-2011, 03:10 PM
passel's Avatar
passelStreadreader and Plink.exe issues in VB.NET passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

If you're sure that it all appears to be working, then you might want to try doing another SW.WriteLine("exit").
The first one you have in your code should cause plink.exe to exit.
The second once should cause cmd.exe to exit.
I believe since cmd.exe isn't exited, then your thread hangs on the SR.ReadToEnd until you close the cmd window yourself.

I would think that there could be timing issues.
You might need to verify that by putting something like
Threading.Thread.Sleep(1000)
between the two "SW.WriteLine("exit")" statements to allow time for plink.exe to actually exit, otherwise both "exit" input would go to plink.

A better option, probably, would be to approach it slightly differently.
I had better success launching plink as an argument to cmd and use the /c option on the command line so that cmd.exe exits automatically when plink exits.

Along these lines:
Code:
Private Sub NDS_Start_SIT_Logic()
  Dim myprocess As New Process
  Dim StartInfo As New System.Diagnostics.ProcessStartInfo()

  StartInfo.FileName = "cmd"
  StartInfo.Arguments = "/c C:\plink.exe " + Unix_User_Name + "@spongeshrimp.grhq.XXX.com -pw " + Unix_User_Password
  StartInfo.RedirectStandardInput = True
  StartInfo.RedirectStandardOutput = True
  StartInfo.UseShellExecute = False
  StartInfo.CreateNoWindow = False 

  myprocess.StartInfo = StartInfo
  myprocess.Start()

  Dim SR As System.IO.StreamReader = myprocess.StandardOutput
  Dim SW As System.IO.StreamWriter = myprocess.StandardInput
  SW.WriteLine("ps -ef | grep nds")
  SW.WriteLine("exit")
  Results = SR.ReadToEnd  
  SW.Close()
  SR.Close()

  Invoke(NDS_Start_SIT_Updater)
End Sub
Of course, once it is working, then I would set CreateNoWindow = True, so you don't have the visual of the cmd window opening up on the desktop, and then closing, since you have the input and output redirected and won't see anything happening in the window itself.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 09-28-2011 at 03:55 PM.
Reply With Quote
  #4  
Old 09-28-2011, 04:07 PM
snarfblam's Avatar
snarfblamStreadreader and Plink.exe issues in VB.NET snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

Is there a reason you are using CMD? From what I can see, you should be able to directly create the process yourself, and you wouldn't have to worry about waiting for CMD.EXE to terminate.
__________________
C# _VB.NET _
Reply With Quote
  #5  
Old 09-28-2011, 04:36 PM
passel's Avatar
passelStreadreader and Plink.exe issues in VB.NET passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Well, that's true.
Plink is a command line executable, so it will launch a command window automatically to run in, so it will be more succinct, and more efficient to let windows create the "command line" environment to run Plink under than do a cmd /c.
The two lines would become
StartInfo.FileName = "c:\plink.exe"
StartInfo.Arguments = Unix_User_Name + "@spongeshrimp.grhq.XXX.com -pw " + Unix_User_Password

You would still want to set CreateNoWindow to True to not see the command window open and close.

In the first case, using cmd /c will create two processes cmd.exe and plink.exe.

In the second case, there is only one process plink.exe, which is running in a command window environment.

The first case there are two command window environments, the one for cmd.exe and the one for plink.exe.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 09-28-2011 at 04:51 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
 
Streadreader and Plink.exe issues in VB.NET
Streadreader and Plink.exe issues in VB.NET
 
-->