Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-21-2015, 09:17 AM
charan314 charan314 is offline
Registered User
 
Join Date: Oct 2015
Posts: 5
file path comparison

Hello,

Using the "LogOutputOfSpecificCommand-UseReadString.vbs" script as an example, I have written my script to capture the output and run series of commands based on the result but the comparison is failing although the MsgBox() output shows correct result. Can anyone help me if I did anything wrong?

When I ran MsgBox(szResult1), the output showed me /usr/bin/bksu.

Here is the snippet.

Code:
If szResult1 = "/usr/bin/bksu" Then
 		crt.Screen.Send "su - produser" & vbCr
 		crt.Sleep 1000
 		crt.Screen.WaitForString "$ "
 		crt.Screen.Send "bash" & vbCr
 		crt.Screen.Clear
          Else
 		MsgBox("None of them work !! Enter manually")
End If
It directly goes to Else statement and prints "None of them work !! Enter manually".

Any help is really appreciated.

Thanks,
Charan
Reply With Quote
  #2  
Old 10-21-2015, 09:31 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Charan,

Thanks for the post.

I ran a quick test, and if the strings that are being compared actual equal each other, then I do enter the If...Then block.

My guess is that the strings you are comparing are subtly different. You might consider using something similar to the following to see if there is anything in the result string that you don't expect:
MsgBox Chr(34) & strResult & Chr(34)
Does this help you find a solution to the problem you are having with your script?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 10-21-2015, 10:43 AM
charan314 charan314 is offline
Registered User
 
Join Date: Oct 2015
Posts: 5
Hi Todd,

I see new line something like this in the dialog box.

Code:
"/usr/bin/bksu
"
I did Trim(szResult1) but that didn't seem to trim the new line character.
Reply With Quote
  #4  
Old 10-21-2015, 01:40 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Charan,

Since you are waiting for the results of what appears to be sending a command to the remote machine, you are likely actually capturing a CR and an LF.

You might try and use the following to capture the output of the command:
crt.Screen.Send "pwd" & vbcr
strResult = crt.Screen.ReadString vbcrlf & "$"
This is an easy way to strip the newline characters. This will fail if the remote is not sending a CR and an LF. You may want to try replacing "vbcrlf" with "vbcr" or "vblf" if you get a failure.

Does this help you accomplish your goal?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 10-21-2015, 02:20 PM
charan314 charan314 is offline
Registered User
 
Join Date: Oct 2015
Posts: 5
Thank you so much Todd for you advise to use chr(34). I dont know why Trim() didn't work but I used Replace() which solved my problem.

Code:
szResult1 = Replace(szResult1, vbCrlf,"")
Reply With Quote
  #6  
Old 10-21-2015, 02:38 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
You are welcome Charan. I am glad I could help.

The Replace() function is a fine way to handle this as well. If you see a failure, just remember that the remote might not be sending both a CR and an LF so you would need to modify your Replace() statement.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:18 AM.