Plink.exe and StdoutRead
-
Recently Browsing 0 members
No registered users viewing this page.
-
Similar Content
-
By noellarkin
This is the AutoIt script I'm using:
#include <AutoItConstants.au3> Local $Python = "C:\Program Files\Python38" Local $Script = "levenstein.py" Local $String1Path = @ScriptDir & "\string1.txt" Local $String2Path = @ScriptDir & "\string2.txt" Local $Arguments = '"' & $String1Path & '" "' & $String2Path & '"' Local $Concat = $Script & " " & $Arguments ConsoleWrite(@CRLF & $Concat) Local $RunIt = Run(@ComSpec & " /c " & $Concat, @ScriptDir, @SW_HIDE, $STDERR_MERGED) $Output = StdOutRead($RunIt) ConsoleWrite(@CRLF & "Output:" & $Output) It calls the following Python script (levenstein.py):
import re import sys import editdistance def main(): # Check if there are 2 command line arguments if len(sys.argv) != 3: print("Error: Two file paths must be provided") return # Read the contents of the files filepath1 = sys.argv[1] filepath2 = sys.argv[2] string1 = read_file_contents(filepath1) string2 = read_file_contents(filepath2) # Calculate and print the similarity between the two strings similarity = calculate_similarity(string1, string2) print(similarity) def read_file_contents(filepath): # Read the contents of a file into a string with open(filepath, 'r') as f: return f.read() def calculate_similarity(string1, string2): # Calculate the similarity between two strings return 100 - (100 * editdistance.eval(string1, string2) / max(len(string1), len(string2))) # Run the main function if __name__ == '__main__': main() It's working when I run it from cmd, but not when I use AutoIt.
My AutoIt console looks like this:
levenstein.py "C:\test\Autoit Python\string1.txt" "C:\test\Autoit Python\string2.txt" Output: Whereas when I run the exact same command in cmd levenstein.py "C:\test\Autoit Python\string1.txt" "C:\test\Autoit Python\string2.txt" I get an output that's more like 77.08934 which is what I would expect from the .py script.
I believe I must be making a mistake in the way I'm using the Run command.
Note: I'm using Python for Edit Distance because the files I'm comparing are rather large, and I'm not sure if the code snippets I found in the Autoit forum would be effective.
-
By p4sCh
Hello everyone,
I've created a UDF for basic communication with SSH servers. I know there is already such a UDF, but I wasn't satisfied with it for my purpose, so I created a new one.
This UDF also acts as a wrapper for the plink executable. Its essential functions are _SSHConnect, _SSHSend, _SSHRecv and _SSHCloseSocket.
It does support multiple simultaneous connections and aims to be pretty robust. Feel free to share your opinions
Two of the included examples use a slightly modified version of Vintage Terminal by @Chimp
Download
The download includes ssh.au3 (UDF), plink.exe (necessary), vintage terminal and code examples:
Version 1.0.1
- fixed rare _SSHConnect bug where "ssh-host-key prompt" was not answered
SSH UDF 1.0.1.zip
-
By JiBe
Hi to all,
I only am accustomed pas has posted on the forum (coz, I'm french). But I use it a lot.
So first of all, thank you all to participate in the evolution of this wonderful product.
Today is not one day like any other, I myself am decide has posted a UDF that I myself create and developed (there may be some bug) for some months.
So here it is:
This UDF allows to use the SSH protocol very easily in your code.
It uses the syntax as the TCPxxx() function.
Your code will be easier to convert :-).
excused my English, I'm French.
Example:
#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.4.0 Author: Joseph Barone 2010-2015 Script Function: Modele pour l'utilisation de la fonction ssh (plink). #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include #include #include #include #include #include "SSH_udf.au3" _SSHStartup() Global $butt[6] $Gui = GUICreate("SSH Console",550,400) $label1 = GUICtrlCreateLabel("Adresse IP:",10,10,150,20) ; ip $input1 = GUICtrlCreateInput("",10,25,150,20) ; ip $label2 = GUICtrlCreateLabel("Tcp port:",170,10,150,20) ; port $input2 = GUICtrlCreateInput("",170,25,60,20) ; port $label6 = GUICtrlCreateLabel("Protocol:",240,10,40,20) ; port $input6 = GUICtrlCreateInput("ssh",240,25,60,20) ; port $butt[0] = GUICtrlCreateButton("Connect0",310,5,80,20,$BS_DEFPUSHBUTTON) $butt[1] = GUICtrlCreateButton("Connect1",390,5,80,20) $butt[2] = GUICtrlCreateButton("Connect2",470,5,80,20) $butt[3] = GUICtrlCreateButton("Connect3",310,25,80,20) $butt[4] = GUICtrlCreateButton("Connect4",390,25,80,20) $butt[5] = GUICtrlCreateButton("Connect5",470,25,80,20) $Checkbox = GUICtrlCreateCheckbox("RSA, Fingerprint, Alert AutoValidate", 330, 45, 205, 25) $label4 = GUICtrlCreateLabel("Login:",10,45,150,20) ; login $input4 = GUICtrlCreateInput("",10,60,150,20) ; login $label5 = GUICtrlCreateLabel("Mot de passe:",170,45,150,20) ; password $input5 = GUICtrlCreateInput("",170,60,150,20,$ES_PASSWORD) ; password $label3 = GUICtrlCreateLabel("Commande a envoyer:",10,85,150,20) ; send command $input3 = GUICtrlCreateInput("",10,100,310,20) ; send commande vers l'hote $butt2 = GUICtrlCreateButton("Send",330,100,80,20,$BS_DEFPUSHBUTTON) GUICtrlSetState($butt2,$GUI_DISABLE) $edit = GUICtrlCreateEdit("",10,130,530,260,$WS_VSCROLL);,$WS_DISABLED)) GUISetState() Global $ConnectedSocket[6] = [-1,-1,-1,-1,-1,-1] Global $msg, $recv, $ret ; GUI Message Loop ;============================================== While 1 $nmsg = GUIGetMsg() If $nmsg = $GUI_EVENT_CLOSE Then ExitLoop ;;; connect part: $b = 0 While 1 If $nMsg = $butt[$b] Then If GUICtrlRead($butt[$b]) = "Connect"&$b Then _SSHParametreSet("yesall",GUICtrlRead($Checkbox)) _SSHParametreSet("protocol",GUICtrlRead($input6)) _SSHParametreSet("login",GUICtrlRead($input4)) _SSHParametreSet("passwd",GUICtrlRead($input5)) $ConnectedSocket[$b] = _SSHConnect(GUICtrlRead($input1),GUICtrlRead($input2)) If $ConnectedSocket[$b] = 0 Then MsgBox(0,"Erreur", "Impossible de ce connecter!!") Else GUICtrlSetData($butt[$b],"Close"&$b GUICtrlSetState($butt2,$GUI_ENABLE) EndIf DisplayArray($_config) ConsoleWrite("nb config:"&$_nbconf&@CRLF) Else _SSHCloseSocket($ConnectedSocket[$b]) GUICtrlSetData($butt[$b],"Connect"&$b GUICtrlSetState($butt2,$GUI_DISABLE) DisplayArray($_config) ConsoleWrite("nb config:"&$_nbconf&@CRLF) EndIf EndIf ;;; send part: If $nMsg = $butt2 Then $ret = _SSHSend( $ConnectedSocket[$b] , GUICtrlRead($input3)&@crlf) GUICtrlSetData($input3,"") GUICtrlSetState($input3,$GUI_FOCUS) EndIf ;;; receive part: $recv = _SSHRecv( $ConnectedSocket[$b]) If $recv <> "" Then GUICtrlSetData($edit, GUICtrlRead($edit) & $recv ) EndIf GUICtrlSendMsg($edit, $EM_SCROLL, $SB_PAGEDOWN, 0) $b += 1 If $b = UBound($butt) Then ExitLoop WEnd WEnd _SSHCloseSocket($ConnectedSocket) _SSHShutdown() Exit Func DisplayArray($array) $i = 0 $j = 0 if UBound($array,1) = 0 Then Return While 1 ConsoleWrite("(["&UBound($array,1)&"]["&UBound($array,2)&"]) ") While 1 ConsoleWrite("["&$j&"]"&$array[$i][$j]&" ") $j += 1 if UBound($array,2)<=$j Then ExitLoop WEnd ConsoleWrite(@CRLF) $i += 1 $j = 0 if UBound($array,1)<=$i Then ExitLoop WEnd EndFunc
I join with UDF version of modified putty myself. 🙂 LoL
but, it is not used with the UDF, it is included in the UDF.
putty-04012015- 92453+lic.zip
ssh_udf.zip
New version (contains the latest version of plink (0.74) edited by http://jakub.kotrla.net/putty/)
ssh_udf-v2.zip
Same as the v2 but supports all putty/plink settings
ssh_udf-v2.1.zip
-
By GillesMaisonneuve
Good morning,
I am trying to read a Unicode utf8 string from a perl subprocess via StdoutRead.
I use an AUtoIt GUI and display result in an 'Edit' control (see my code below) using 'Courier New', a font that can handle Unicode characters.
I was expecting a result looking like (CMD console):
++$ chcp 65001>NUL: & perl -Mutf8 -CS -e "use 5.018; binmode STDOUT,q(:utf8); say qq(\x{03A9})" & chcp 850>NUL: Ω Instead I get someting like this (see downward the screen copy):
++$ chcp 1250>NUL: & perl -Mutf8 -CS -e "use 5.018; binmode STDOUT,q(:utf8); say qq(\x{03A9})" & chcp 850>NUL: Ω Obviously while I was expecting to receive an utf8 char, it seems to have been converted to Windows ANSI codepage 1250 (Windows default for Western/Central Europe, right ?)
What am I doing wrong? Is there someone who could guide me?
Here is my code and my output in the GUI.
Creating and configuring the Edit control:
Local $Edit1 = GUICtrlCreateEdit( "", 20, 110, 780, 500, BitOr($GUI_SS_DEFAULT_EDIT,$ES_MULTILINE,$ES_READONLY) ) GUICtrlSetData($Edit1, "This field will contain text result from external Perl command") GUICtrlSetFont($Edit1, 10, $FW_THIN, $GUI_FONTNORMAL, "Courier New")
Executing Perl command (note: `-Mutf8` and `-CS` garantees that I work in utf8 and STDOUT accepts wide-characters):
local $ExePath = 'perl.exe -Mutf8 -CS ' ;~ if perl in PATH, no need for full path C:\Perl\bin\perl.exe local $Params = '-e "use 5.018; use utf8; use charnames q(:full); binmode STDOUT,q(:utf8);' & _ 'say scalar localtime; say qq(\N{GREEK CAPITAL LETTER OMEGA})"' local $Cmd = $ExePath & ' ' & $Params Local $iPID = Run($Cmd, "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))
Reading STDOUT and displaying it into the Edit control:
While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd If $sOutput <> '' Then GUICtrlSetData($Edit1, $sOutput) EndIf
And now, what I get on my GUI:
-
By Funtime60
I have a Parent Script that starts multiple, concurrent child processes. I cannot figure out how to apply the technique for using StdoutRead in the examples in a way that listens to them all simultaneously.
For reference, there can be any even number of, or single, child processes and there is an 1D array, $PIDS, that stores the PIDS of all the child processes and they should be outputting to another 1D array $sOutput.
Thank you for your time. Please just point me in the right direction. I'm sorry if I missed another topic that covers this.
-
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now