Jump to content

Dont work StdoutRead with Putty.exe


nill
 Share

Recommended Posts

$user = "root"
$password =""
$host ="5.0.0.1"
$port ="22"

$puty_exe = @ScriptDir & "\putty.exe"; putty salve local folder script


$command = Run(@comspec & " /C "&$puty_exe&" -ssh -l "&$user&" "&$host&" p "&$port&" -pw "&$password,@ScriptDir, @SW_HIDE, 1)
While 1
$data = StdoutRead($command)
ConsoleWrite($data&@CRLF)
If @error Then ExitLoop
Wend

Why StdoutRead cant read what putty.exe write in console ?

Edited by nill
Link to comment
Share on other sites

Because you missed to set parameter opt_flag of the Run statement to $STDOUT_CHILD

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

 

2 hours ago, water said:

Because you missed to set parameter opt_flag of the Run statement to $STDOUT_CHILD

Please give me work example

I try many variants

Edited by nill
Link to comment
Share on other sites

Don't know if or where are your misatake(s). Run this script:

$user = "root"
$password = ""
$host = "5.0.0.1"
$port = "22"

$puty_exe = @ScriptDir & "\putty.exe"; putty salve local folder script
If Not FileExists($puty_exe) Then
    ConsoleWrite('putty not found' @CRLF)
    Exit
EndIf

$iPID = Run(@ComSpec & " /C " & $puty_exe & " -ssh -l " & $user & " " & $host & " p " & $port & " -pw " & $password, @ScriptDir@SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD)
;change back to @SW_HIDE after script is successfully tested
$i = 0
While 1
    $sOutput = StdoutRead($iPID)
    If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
        ExitLoop
    EndIf
    ConsoleWrite("Stdout Read" & $i & ": " & $sOutput&@CRLF)
WEnd
$i = 0
While 1
    $i += 1
    $sOutput = StderrRead($iPID)
    If @error Then ; Exit the loop if the process closes or StderrRead returns an error.
        ExitLoop
    EndIf
    ConsoleWrite("Stderr Read" & $i & ": " & $sOutput&@CRLF)
WEnd
ConsoleWrite('Finished'&@CRLF)

and post output of the Sciteconsole.

Link to comment
Share on other sites

"I try many variants" and "don't help" aren't very informative. Please describe what's going wrong. What are (if any) your error messages? Does it work if you do it manually through the commandline?

One suggestion I would offer is to store the command you're executing in a temporary variable and writing it to the console (ConsoleWrite()) to see if you're actually executing the thing that you meant to execute.

Another suggestion, maybe that's the whole thing, is that the -p parameter for putty requires the dash, so change " p " & $port to " -p " & $port.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

AutoBert

you have erorr in code after i run your code i see this

$PID = Run(@ComSpec & " /C "&$puty_exe&" -ssh -l " & $user & " " & $host & " p " & $port & " -pw " & $password, @ScriptDir^ ERROR

but nothing change i cant read console in autoit

SadBunny

I dont have erorr massage but autoit nothing return in  StdoutRead after I run putty

with  dash  -p I have error

I run another program call vmrun.exe (from VMware) and I can read console

If you can just run putty.exe from autoit maybe I can see simple things

 

Link to comment
Share on other sites

1 hour ago, nill said:

you have erorr in code after i run your code i see this

sorry, i didn't test, please test this:

#include <AutoItConstants.au3>

$user = "root"
$password = ""
$host = "5.0.0.1"
$port = "22"

$puty_exe = @ScriptDir & "\putty.exe"; putty salve local folder script
If Not FileExists($puty_exe) Then
    ConsoleWrite('putty not found' &@CRLF)
    Exit
EndIf

$iPID = Run(@ComSpec & " /C " & $puty_exe & " -ssh -l " & $user & " " & $host & " p " & $port & " -pw " & $password, @ScriptDir,@SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD)
;change back to @SW_HIDE after script is successfully tested
$i = 0
While 1
    $sOutput = StdoutRead($iPID)
    If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
        ExitLoop
    EndIf
    ConsoleWrite("Stdout Read" & $i & ": " & $sOutput&@CRLF)
WEnd
$i = 0
While 1
    $i += 1
    $sOutput = StderrRead($iPID)
    If @error Then ; Exit the loop if the process closes or StderrRead returns an error.
        ExitLoop
    EndIf
    ConsoleWrite("Stderr Read" & $i & ": " & $sOutput&@CRLF)
WEnd
ConsoleWrite('Finished'&@CRLF)

and please post console output after, mine output is:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Bert\AutoIt3.My\Test\test.au3" /UserParams    
+>23:58:54 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
+>Check for missing standard constants/udf include files: 1 include(s) were added
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Test\test.au3
+>23:58:57 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files\AutoIt3\autoit3.exe "C:\Users\Bert\AutoIt3.My\Test\test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
putty not found
+>23:58:57 AutoIt3.exe ended.rc:0
+>23:58:57 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 4.018

 

Link to comment
Share on other sites

AutoBert

in outputs i see this

>"C:\Program Files\AutoIt3\SciTE\..\AutoIt3.exe" /ErrorStdOut "C:\Users\ADMIN\Desktop\putty\test_putty.au3"    
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 
Stdout Read0: 

 

many Stdout Read0:  script never end

Link to comment
Share on other sites

  • Developers

Why would Putty have a STDOUT and STDERR data stream as it is a regular Windows program?
 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Use PLink. That's the command line tool for Putty. You'll find a lot of examples on the forum. 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@Jos, yes: Pscp and plink.  

3.7 The PuTTY command line

       PuTTY can be made to do various things without user intervention
       by supplying command-line arguments (e.g., from a command prompt
       window, or a Windows shortcut).

Look for the verbose mode. putty command line

GUI Putty should have a tick box for a log file. It may help to force putty into verbose mode.  See if you can log the output to a file.  Read the file afterwards.

 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

It does not work with putty, only with plink. I've tried running it with putty for ages and failed. Since i don't have code in hand, i will describe how it works - open putty, save some session, then launch the plink proccess with the same session name. Write to sdin, wait some time , close proccess and then read stdout and stderr.

#include <constants.au3> ; not sure where was the child stuff stored
$somepid = run("c:\path\to\plink.exe -batch NameOfYourStoredConnection ","c:\path\to\", @sw_show $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
StdinWrite($somepid,"do stuff here")
sleep(100)
ProccessClose($somepid)
ProccessWaitClose($somepid)
$Output = StdoutRead($somepid)
$Error = StderrRead($somepid)
consolewrite("output - " & $Output & @CRLF)
consolewrite("error (if any) - " & $Error & @CRLF)
exit

Something like this (quick writed in box, hope you get the idea)

Edit : typos, i need english dictionary :D

Edited by JustSomeone
Link to comment
Share on other sites

water

JustSomeone

 

try to use plink.exe instead putty.exe

#include <AutoItConstants.au3>

$user = "root"
$password = "pass"
$host = "1.1.1.1"
$port = "22"

$puty_exe = @ScriptDir & "\plink.exe"; putty salve local folder script
If Not FileExists($puty_exe) Then
    ConsoleWrite('putty not found' &@CRLF)
    Exit
EndIf

$iPID = Run(@ComSpec & " /C " & $puty_exe & " -ssh -l " & $user & " " & $host & " p " & $port & " -pw " & $password, @ScriptDir,@SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD)
;change back to @SW_HIDE after script is successfully tested
$i = 0
While 1
    $sOutput = StdoutRead($iPID)
    If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
        ExitLoop
    EndIf
    ConsoleWrite("Stdout Read" & $i & ": " & $sOutput&@CRLF)
WEnd
$i = 0
While 1
    $i += 1
    $sOutput = StderrRead($iPID)
    If @error Then ; Exit the loop if the process closes or StderrRead returns an error.
        ExitLoop
    EndIf
    ConsoleWrite("Stderr Read" & $i & ": " & $sOutput&@CRLF)
WEnd
ConsoleWrite('Finished'&@CRLF)

I get this text in autoit console

Stdout Read0: root@1.1.1.1's password: 

but why i cant login in on server ?

when I use this in putty.exe all is ok I login on server

when I mannually run plink.exe password requires too

 

I cant use StoredConnection like in JustSomeone example

Link to comment
Share on other sites

  • Developers

You are not having the correct parameter for port: change the " p " to " -P ".

$iPID = Run(@ComSpec & " /C " & $puty_exe & " " & $host & " -ssh -l " & $user & " -pw " & $password & " -P " & $port , @ScriptDir,@SW_MAXIMIZE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD )

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...