loganch / AutoIt-VSCode

AutoIt Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=Damien.autoit
MIT License
74 stars 25 forks source link

How to get output from the script when running from command prompt #198

Open kcvinker opened 1 year ago

kcvinker commented 1 year ago

Hi, I am running my au3 script using Cmder. This is my command.

AutoIt3_x64.exe AutoIt3Wrapper.au3 /run /prod /ErrorStdOut /in myScript.au3

This will run my script but I can't see any outputs on Cmder window. Same is happening when I run this using Windows cmd. How to get the output from my script. Edit : By "Output" I mean the result of "ConsoleWrite" function.

vanowm commented 1 year ago

if you run this directly in cmder, without vscode, can you see the output then? Autoit output in vscode has it's own "output" window, it doesn't show anything in debug console.

kcvinker commented 1 year ago

@vanowm First of all, thank you for reply. Well, that's a complex story and at last, after a few day's try, I succeeded in displaying outputs in cmder or conemu. It's nothing but a python script which will start conemu with the command to run AutoIt3.exe with au3 stripper and other parameters including our script file. our script is a command line argument to this python script. Which we can pass directly to cmd window or by using vs code/sublime's build systems.
This script will start au3 interpreter and read the stdout & stderr from two different threads and print them to console in real time. I wrote about this in the forum. So now, I can run my au3 scripts from literally anywhere.

vanowm commented 1 year ago

I'm a bit confused here... If you launching your autoit scripts through python script, it bypasses AutoIt-VSCode all together... if you launching it through AutoIt-VSCode, then it bypasses your python script and since it doesn't use any command prompt/terminal, there nothing can be output there either... I could be wrong, but my understanding how output streams work, is parent process can read the stream and if you launch script through vscode, then your cmder is not the parent process and therefor can't read the output. In which case your best bet is to modify your scripts to output directly into cmder window.

kcvinker commented 1 year ago

@vanowm Let me explain a little more. I am running python in conEmu. It interprets my python script. My au3 script is the command line argument for my python script. So my python script's child process is AutoIt3.exe. Therefore, my python script receives outputs from autoit3. Now, this is how I run my scripts in vs code & sublime and direct command line.

  1. VS Code I am using actBoy168's "Tasks" extension. With that, we can have taskbar labels of our own. If we click that label, the task associated to that label will run.
    {
            "label": "AutoIt",
            "options": {
                "statusbar": {
                    "hide": false // We can hide if don't want this entry
                }
            },
            "type": "shell",
            "command": "ConEmu64",
            "args": [
                "-Dir",
                "My_Working_Dir",
                "-run",
                "python",
                "my_python_script_to_run_au3.py",
                "$fileName",
                "&",
                "exit"
            ],
            "presentation": {
                "echo": true, 
                "reveal": "never", // Means, no need to show the vs code's own terminal.
                "focus": false, 
                "panel": "shared",
                "showReuseMessage": false,
                "clear": true 
            }
        },
  2. Sublime Text In sublime's build system, I added my own system to run my scripts.
    "cmd": ["ConEmu64", "-Dir", "$file_path",
                "-run",
                "python",
                "my_python_script_to_run_au3.py", 
                "$file"
            ],
    "quiet" : true,  // We don't need sublime's own console.

    And now I have plans for making my own console instead of using conEmu. By that way, I can inspect the output and if there is no errors, I can close the console window automatically. In order to do that, I need to write a wrapper for scintilla editor