noellarkin Posted December 24, 2022 Posted December 24, 2022 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.
Developers Jos Posted December 24, 2022 Developers Posted December 24, 2022 (edited) I would start with changing the cmd param to this for testing to show&keep the window open in case of any errors: Local $RunIt = Run(@ComSpec & " /k " & $Concat, @ScriptDir, @SW_SHOW, $STDERR_MERGED) EDIT: And it could very well be you need to run this in x64 in stead of x86! Edited December 24, 2022 by 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.
noellarkin Posted December 24, 2022 Author Posted December 24, 2022 (edited) Thanks, I tried out your suggestion - - the cmd window flashes for half a second and disappears, and the ConsoleOutput is the same as before. When you say I have to run it in x64, what would I need to do, exactly? I will be inegrating this script into others that have all been written in x32, so I'm wondering how that would work out... Edited December 24, 2022 by noellarkin clarity
Developers Jos Posted December 24, 2022 Developers Posted December 24, 2022 8 minutes ago, noellarkin said: the cmd window flashes for half a second and disappears, /k should keep it open...? 9 minutes ago, noellarkin said: run it in x64, what would I need to do, exactly? You need to run your script with AutoIt_x64.exe, which can be done with an directive when you have the Full SciTE4AutoIt3 installed: #AutoIt3Wrapper_UseX64=y 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.
noellarkin Posted December 24, 2022 Author Posted December 24, 2022 /k doesn't seem to keep the window open, just flash it for a second. I tried this: #AutoIt3Wrapper_UseX64=y #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 & " /k " & $Concat, @ScriptDir, @SW_SHOW, $STDERR_MERGED) ConsoleWrite(@CRLF & "RunIt:" & $RunIt) $Output = StdOutRead($RunIt) ConsoleWrite(@CRLF & "Output:" & $Output) same issues on output. I've made a test case and attached a zip file. Test.zip
noellarkin Posted December 24, 2022 Author Posted December 24, 2022 Also tried compiling the .py into an exe file and tried this: #AutoIt3Wrapper_UseX64=y #include <AutoItConstants.au3> Local $Python = "C:\Program Files\Python38" Local $Script = "levenstein.exe" 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 & " /k " & $Concat, @ScriptDir, @SW_SHOW, $STDERR_MERGED) ConsoleWrite(@CRLF & "RunIt:" & $RunIt) $Output = StdOutRead($RunIt) ConsoleWrite(@CRLF & "Output:" & $Output) Working via cmd but not via ComSpec levenstein.exe
Developers Jos Posted December 24, 2022 Developers Posted December 24, 2022 10 minutes ago, noellarkin said: Also tried compiling the .py into an exe file and tried this: No need for that, so show me the whole SciTE ouputpane info when you run this. 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.
noellarkin Posted December 24, 2022 Author Posted December 24, 2022 using levenstein.py >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Test\AutoIt.au3" /UserParams +>20:17:00 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\DESKTOP\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\DESKTOP\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Test\AutoIt.au3 +>20:17:00 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Test\AutoIt.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. levenstein.py "C:\Test\string1.txt" "C:\Test\string2.txt" RunIt:2956 Output:+>20:17:01 AutoIt3.exe ended.rc:0 +>20:17:01 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.016 Using levenstein.exe >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Test\AutoIt.au3" /UserParams +>20:18:36 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\DESKTOP\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\DESKTOP\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Test\AutoIt.au3 +>20:18:37 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Test\AutoIt.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. levenstein.exe "C:\Test\string1.txt" "C:\Test\string2.txt" RunIt:3400 Output:+>20:18:37 AutoIt3.exe ended.rc:0 +>20:18:37 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.248
Developers Jos Posted December 24, 2022 Developers Posted December 24, 2022 27 minutes ago, noellarkin said: "C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" You are not using the separate Full SciTE4Autoit3 version but the one that came with AutoIt, so the AutoIt3Wrapper directive doesn't do anything! Either install that extra installer and benefit from it's extra's or use the internal available: #pragma compile(x64, true) ... to run the script as x64. 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.
Solution noellarkin Posted December 24, 2022 Author Solution Posted December 24, 2022 (edited) Thanks for the suggestions. I managed to fix the issue, here's what worked: #include <AutoItConstants.au3> Local $Python = "C:\Program Files\Python38" Local $Script = "levenstein.exe" 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) ProcessWaitClose($RunIt) $Output = StdOutRead($RunIt) ConsoleWrite(@CRLF & "Output:" & $Output) It needed that extra line "ProcessWaitClose" Edited December 24, 2022 by noellarkin exe
Developers Jos Posted December 24, 2022 Developers Posted December 24, 2022 6 minutes ago, noellarkin said: It needed that extra line "ProcessWaitClose" Yea .... that makes sense ! noellarkin 1 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.
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