kcvinu Posted May 25, 2023 Posted May 25, 2023 Hi all, I am trying to run my autoit script from Sublime Text editor. I am using a python script for this. These are the arguments that I uses. argList.append("C:\\Program Files (x86)\\AutoIt3\\AutoIt3_x64.exe") argList.append("C:\\Program Files (x86)\\AutoIt3\\SciTE\\AutoIt3Wrapper\\AutoIt3Wrapper.au3") argList.extend(["/run", "/prod", "/ErrorStdOut", "/in"]) argList.append("C:\\Users\\kcvin\\OneDrive\\Programming\\D Lang\\AutoWings\\dflex-au3\\app.au3") subprocess.run(argList) I can successfully run my script and I can see the window up and running. But the problem is I don't get any outputs from AutoIt3_x64. If any errors in the script, I will not get any error messages. How to fix this ? Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
kcvinu Posted June 5, 2023 Author Posted June 5, 2023 (edited) Hi all, I found the answer by myself. I am happy to share the answer for future readers. At first, I thought that Autoit interpreter is only worked well with Scintilla editor. Because, when I tried to run my au3 script in notepad++ with "NppExec" plugin, it amazingly shows the real time outputs in console. But I was wrong. Autoit will emit program outputs at real time and we need to catch it from stdout or stderr. So this python script will work. expandcollapse popupimport subprocess import threading // We need to omit unnecessary clutter from our console. So exclude the output with these words. excluded_words = ["Starting AutoIt3Wrapper", "Running AU3Check", "AU3Check ended", ">Running", "+>Setting Hotkeys", "AutoIt3.exe ended", " AutoIt3Wrapper Finished"] // But we need to check the return codes. If something went terribly wrong, we need that line in console. result_words = ["AU3Check ended", "AutoIt3.exe ended" ] success_result = "rc:0" // If 'rc' os anything other than 0, we need to see iit def is_exluded_line(text): // if this returns True, we don't need 'text' to be printed in console. found = any(word in text for word in excluded_words) if found: end_result = any(word in text for word in result_words) if end_result: if not success_result in text: return False return True else: return False // This function will collect the program output and display it in console. def read_output(stream): outNum = 1 // I like a counter, bcause, it's easy to analyse the output. for line in stream: // Process and handle the output line if not is_exluded_line(line): print(f"[{outNum}] {line.strip()}") outNum += 1 // This functions spawns two different threads and collect the program outputs def capture_output(command): // Run the command and capture the stdout and stderr in real-time process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) // Create separate threads to read from stdout and stderr stdout_thread = threading.Thread(target=read_output, args=(process.stdout,)) stderr_thread = threading.Thread(target=read_output, args=(process.stderr,)) // Start the threads to capture the output in real-time stdout_thread.start() stderr_thread.start() // Wait for the process to finish and the threads to complete process.wait() stdout_thread.join() stderr_thread.join() print("AutoIt3 Exited............................") // We want to see a nice reminder that everything has been ended. argList = ["cmd", "/c", "cd"] // We will run command prompt. argList.append(r"path to your working directory") // cmd will change to that directory argList.append("&&") // After running the cd command, argList.append(r"C:\Program Files (x86)\AutoIt3\AutoIt3_x64.exe") // We need to start AutoItx3.exe and AutoIt3Wrapper. argList.append("C:\\Program Files (x86)\\AutoIt3\\SciTE\\AutoIt3Wrapper\\AutoIt3Wrapper.au3") argList.extend(["/run", "/ErrorStdOut", "/in"]) argList.append("your_script.au3") // Now run the command with our function capture_output(argList) How to run your au3 scripts with this python script ? Just open command prompt and run your python script like this; python "your_script_to_run_au3.py" Edited June 5, 2023 by kcvinu Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
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