#1
|
|||
|
|||
Problem using readString()
Hi all,
First of all happy new year 2012! I'm trying to read a simply date shell response but I can't. I was reading another threads related with this, also I was reading scripting pdf but with unsuccesful results. Code:
fecha = "date ""+%Y%m%d%H%M%S""" crt.Screen.Synchronous = True crt.screen.send fecha & vbcr strResult = crt.Screen.ReadString (vbcr) & vbcr crt.screen.send strResult & vbcr Code:
Last login: Tue Jan 10 12:56:18 2012 from 10.237.3.75 date "+%Y%m%d%H%M%S" Last login: Tue Jan 10 12:56:18 2012 from 10.237.3.75 nmsguest@tb2i2kb:~> date "+%Y%m%d%H%M%S" 20120110135908 nmsguest@tb2i2kb:~> Last login: Tue Jan 10 12:56:18 2012 from 10.237.3.75 -bash: Last: command not found nmsguest@tb2i2kb:~> nmsguest@tb2i2kb:~> Could someone help me please? Thanks in advance. Cheers |
#2
|
|||
|
|||
Hi jeraxx,
Thanks for the question. I have included code that may help you accomplish your goal. The example includes comments to explain what the code is doing, and information on using MsgBox to help troubleshoot the code. Code:
fecha = "date ""+%Y%m%d%H%M%S""" crt.Screen.Synchronous = True crt.Screen.Send fecha & vbcr ' Wait for command to be echoed back from remote. This will prevent ' ReadString() from capturing the command that was sent. crt.Screen.WaitForString vbcr ' Read from the prompt to the command. This should capture the required data. ' By including the prompt in the command, the prompt will not be captured. strResult = crt.Screen.ReadString("nmsguest@tb2i2kb:~>") ' You may want to see what was captured prior to sending it to ensure that it is ' the correct data. If the variable contains more information that you need, ' you can use VBScript functions to remove the unwanted information. ' MsgBox strResult crt.Screen.Send strResult & vbcr |
#3
|
|||
|
|||
Hi friend,
I tried to use your code but I obtain this: Code:
Last login: Tue Jan 10 15:21:08 2012 from 10.237.3.75 date "+%Y%m%d%H%M%S" nmsguest@tb2i2kb:~> date "+%Y%m%d%H%M%S" 20120110153906 nmsguest@tb2i2kb:~> nmsguest@tb2i2kb:~> nmsguest@tb2i2kb:~> date "+%Y%m%d%H%M%S" 20120110153906 nmsguest@tb2i2kb:~> nmsguest@tb2i2kb:~> nmsguest@tb2i2kb:~> nmsguest@tb2i2kb:~> Thanks for your assistance Last edited by jeraxx; 01-10-2012 at 07:49 AM. |
#4
|
|||
|
|||
Hi jeraxx,
Thanks for the update. What do you see if you message box the results of reading the output? You would need to uncomment the MsgBox strResult line of code. For example: Code:
fecha = "date ""+%Y%m%d%H%M%S""" crt.Screen.Synchronous = True crt.Screen.Send fecha & vbcr ' Wait for command to be echoed back from remote. This will prevent ' ReadString() from capturing the command that was sent. crt.Screen.WaitForString vbcr ' Read from the prompt to the command. This should capture the required data. ' By including the prompt in the command, the prompt will not be captured. strResult = crt.Screen.ReadString("[nmsguest@tb2i2kb:~>") ' You may want to see what was captured prior to sending it to ensure that it is ' the correct data. If the variable contains more information that you need, ' you can use VBScript functions to remove the unwanted information. MsgBox strResult crt.Screen.Send strResult & vbcr Last edited by rtb; 01-10-2012 at 08:26 AM. |
#5
|
|||
|
|||
Hi again Rtb,
I can see complete command In the message box : date "+%Y%m%d%H%M%S", not the timestamp I'm looking for. What could be happening? Cheers |
#6
|
|||
|
|||
Hi jeraxx,
Would you post the code you are using now? |
#7
|
|||
|
|||
Hi Rbt,
here you are: Code:
fecha = "date ""+%Y%m%d%H%M%S""" crt.Screen.Synchronous = True crt.screen.send fecha & vbcr crt.Screen.waitforstring vbcr strResult = crt.Screen.ReadString ("nmsguest@tb2i2kb:~>") MsgBox strResult crt.screen.send strResult & vbcr |
#8
|
|||
|
|||
Hi jeraxx,
Thanks for the information. Would you send two raw logs to support@vandyke.com with a subject of Attn: Todd - Forum thread 10239? Here is how you can create a raw log: I would like to get a raw log capturing you manually issuing the command, and one where you run the script. |
#9
|
|||
|
|||
sent!
but I think both logs do not clarify too much ... Thank you Rbt |
#10
|
|||
|
|||
Hi jeraxx,
Thanks for the raw logs. It turns out that I missed a simple problem in the script initially, and when I ran my tests on the code I posted, I didn't encounter the timing issue that you are encountering. Here is a new example that should help resolve the issue: Code:
fecha = "date ""+%Y%m%d%H%M%S""" crt.Screen.Synchronous = True ' Ensure that the remote is ready to receive a command. Timeout after 1 second ' if the prompt is not found because we can be fairly certain that the prompt ' has already been received. crt.Screen.WaitForString ">", 1 crt.Screen.Send fecha & vbcr ' Wait for command to be echoed back from remote. This will prevent ' ReadString() from capturing the command that was sent. crt.Screen.WaitForString vbcr ' Read from the carriage return/linefeed after the command to the carriage ' return we sent when issuing the command. This should capture the required ' data. It should also avoid having to trim the data we read. strResult = crt.Screen.ReadString(vbcrlf) ' You may want to see what was captured prior to sending it to ensure that it is ' the correct data. If the variable contains more information that you need, ' you can use VBScript functions to remove the unwanted information. ' MsgBox strResult crt.Screen.Send strResult & vbcr |
#11
|
|||
|
|||
cool !!
Now it works! Thank you very much Todd!! Cheers Juanjo |
#12
|
|||
|
|||
You are welcome Juanjo. I am glad to hear of your success.
Please post any other scripting questions you might have. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|