BreakBadSP BreakBadSP - 6 months ago 133
Python Question

How to pass command line arguments to a Python script / AnyScript while executing it from autoit ShellExecute()

I want to execute one python script from autoit using autoit built-in function ShellExecuteWait().

My Attempt:

$x = ShellExecuteWait("E:/Automation/Python/Scripts/", '-f "file.log" -k "key" -e "errMsg" ')
If @error Then

After running this, I can see some process id in '$x' and '@error' also set to 0. Means Autoit is launching some process.

But my Python script is not producing results (it create results in one txt file) which it is producing when executed independently.

Seems like problem is with the passing cmd args when we execute my python from ShellExecute() i.e.

ShellExecuteWait("E:/Automation/Python/Scripts/", '-f "file.log" -k "key" -e "errMsg" ')

How can I pass cmd args with ShellExecuteWait() method?

Syntax of ShellExecuteWait():

ShellExecuteWait ( "filename" [, "parameters" [, "workingdir" [, "verb" [, showflag]]]] )


filename :- The name of the file to run (EXE, .txt, .lnk, etc).

parameters :- [optional] Any parameters for the program. Blank ("") uses none.

but this Information is not enough (No examples with for use of parameters ).
Note: no problem with my python script and my Python script requires 3 cmd line argv's (strings) with options -f -k and -e


ShellExecuteWait() method details:

My question is extension to this Stack Overflow question: how-to-run-or-execute-python-file-from-autoit ++How to pass CMD args

Answer Source

First, check what the path to your python binary e.g. Python.exe (wherever your python program/binary is located) in your window's system environment/path.

How to run or execute python file from autoit

If path is there then your code must work. In $x you will receive return exit code of python script.

Also you can try to use

RunWait('full_path\Python.exe -f "file.log" -k "key" -e "errMsg"', 'full_path_of_working_directory')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download