Jump to content

Recommended Posts

Posted (edited)

Hi.

Basically, I am trying to telnet to a server, then send commands. This all works fine, except when hidden.

This script asked user for information, then telnets to server (creates log file to read - so script knows when the search either found results or not), logs in, then does lookup and returns results in msgbox. All telnet/DOS functions need to be hidden.

See code snippet.....

I have looked at controlsend, but the dos window has no controlID.

I am new and this is probably sloppy coding and I am probably missing the obvious......

$VOLUME= InputBox("Volume","Please type the volume to search")

$i = 10
Dim $line
Dim $x
Dim $file


Run("cmd.exe")
Sleep(1000)
Send('telnet -f C:\test.txt SERVER_NAME 23{ENTER}')
Sleep(1000)
Send("acssa{ENTER}")
Sleep(1000)
Send("PASSWORD{ENTER}")
Sleep(3000)
Send("vt100{ENTER}")
Sleep(2000)
Send("q vol ")
Send( $VOLUME )
Send("{ENTER}")


$file = FileOpen("c:\test.txt", 0)

$x = 0

While 1
    $line = FileReadLine($file,26)
; msgbox(1,"Line that was read is.....",$line)
    $x = 1
    Sleep(100)
    $IT=StringInStr($line,"Home",0,1)
; MsgBox(1, "IT is", $IT)
; MsgBox(1, "X ", $x ,1)
; MsgBox(1, "Line after stringinstr", $x & " " & $line,1)
    
    If $x = 1 And StringInStr($line, "Home", 0, 1) > 0 Then
        If Not WinActive("Telnet SERVER_NAME", "") Then WinActivate("Telnet SERVER_NAME", "")
        WinWaitActive("Telnet SERVER_NAME", "")
        Send("log{ENTER}")
        WinClose("Telnet SERVER_NAME", "")
; Send("exit{ENTER}")
        msgbox(1,"Results", $VOLUME & " is in the silo.")
        ExitLoop
    EndIf
    
        If $x = 1 And StringInStr($line, "ejected", 0, 1) > 0 Then
        If Not WinActive("Telnet SERVER_NAME", "") Then WinActivate("Telnet SERVER_NAME", "")
        WinWaitActive("Telnet SERVER_NAME", "")
        Send("log{ENTER}")
        WinClose("Telnet SERVER_NAME", "")
; Send("exit{ENTER}")
        msgbox(1,"Results", $VOLUME & " is NOT in the silo.")
        ExitLoop
    EndIf
    
        If $x = 1 And StringInStr($line, "found", 0, 1) > 0 Then
        If Not WinActive("Telnet SERVER_NAME", "") Then WinActivate("Telnet SERVER_NAME", "")
        WinWaitActive("Telnet SERVER_NAME", "")
        Send("log{ENTER}")
        WinClose("Telnet SERVER_NAME", "")
; Send("exit{ENTER}")
        msgbox(1,"Results", $VOLUME & " is NOT in the silo.")
        ExitLoop
    EndIf
    
WEnd

FileClose($file)

FileDelete ( $file )

Exit

Thanks in advance for all suggestion.

Edited by lhk69
Posted

  Manadar said:

Don't have much time: StdIn and StdOut

Not easy, good luck :D

thanks, I'll try tomorrow.

btw, like your avatar pic.

Posted

I am having a difficult time getting stdin and sdtout to work. Keepsa claiming unknown function. I have included constants. Any ideas, or other suggestions?

Posted

  lhk69 said:

I am having a difficult time getting stdin and sdtout to work. Keepsa claiming unknown function. I have included constants. Any ideas, or other suggestions?

Have to be running Beta to use StdInWrite() and StdOutRead().

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

ok, I installed the bata in another dir, but wasnt pointing to it properly. I am now.

here is a code snippet...

$MyTelnet = Run(@COMSPEC & " /c " & "telnet -f C:\telnet_log.txt server1 23","",$STDIN_CHILD + $STDOUT_CHILD)
MsgBox(4096, "", $MyTelnet )
StdinWrite( $MyTelnet, "username" & @CRLF & "password" & @CRLF)
StdinWrite( $MyTelnet )
Exit

opens telnet window, and connects. Never seems to pass the text specified in StdinWrite to the process.

What am I missing?

thank you very much.

Posted

  lhk69 said:

$MyTelnet = Run(@COMSPEC & " /c " & "telnet -f C:\telnet_log.txt server1 23","",$STDIN_CHILD + $STDOUT_CHILD)

What am I missing?

Welcome to the forums!

Your Run function is missing the "show" flag. Try this:

$MyTelnet = Run(@COMSPEC & " /c " & "telnet -f  C:\telnet_log.txt server1 23", "", @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD)
Once you've got your process debugged you can switch it to @SW_HIDE.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Posted (edited)

ok, here is what I have now.

$MyTelnet = Run( "telnet -f  C:\telnet_log.txt server1 23", "", @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
MsgBox(4096, "ProcessID is....", $MyTelnet )
StdinWrite( $MyTelnet, "acsss" & @CRLF )
sleep (1000)
StdinWrite( $MyTelnet, "" & @CRLF )
sleep (2000)
StdinWrite( $MyTelnet, "vt100" & @CRLF )
sleep (2000)
StdinWrite( $MyTelnet, "q vol " & @CRLF & $VOLUME)
StdinWrite( $MyTelnet )

what happens now, is I see the telnet window flash for a milisecond, then nothing is sent to it.

Then the script continues, but of course with no results.

Any ideas? Am I missing another parameter.

I dont think I can use controlsend, because there is no control ID to send to a dos window.

Edited by lhk69
  • 4 weeks later...
  • 6 years later...
Posted

I was looking for a way to send a command to a dos window as well. AzKay's post worked for me, using ControlSend() with @ComSpec. You don't need a Control_ID, you can leave it blank like he wrote it.

  • Moderators
Posted

lordsprinkles,

Do you really think he is going to read your post, or is even interested in it, after 7 years absence from the forum? :huh:

Please look at the dates of the thread in future. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...