1

I am trying to run python script with arguments using WinAPI function ShellExecuteW.

It looks like a

python .\PythonDLL_Example.py 125960 126110 126070 126250 3928 274353.845945816 119761.8349277858 18080.59072693367 -252416.3714632094 -79682.09253258759 -12446.11663140202

I tried to do like this using full paths, just in case:

ShellExecuteW(NULL, NULL, "C:\\Users\\Amber\\AppData\\Local\\Programs\\Python\\Python37\\python.exe", "C:\\Users\\Amber\\AppData\\Roaming\\MetaQuotes\\Terminal\\DEA332DEFF5165CB2EAFB6F9BD062C50\\MQL5\\Experts\\Advisors\\PythonDLL_Example.py 125960 126110 126070 126250 3928 274353.845945816 119761.8349277858 18080.59072693367 -252416.3714632094 -79682.09253258759 -12446.11663140202", NULL, 10);

No result Error %d42

Test execution like below run successfully:

ShellExecuteW(NULL, "open", "C:\\Windows\\Notepad.exe", NULL, NULL, 10);

Please, ho to execute my script?

Thank you

2
  • 2
    Why are you using ShellExecute() for this. Since you are trying to invoke python.exe directly, you should be using CreateProcess() instead Commented Jul 18, 2019 at 22:32
  • Remy is correct. Use CreateProcess for this. Even then, you'll need to supply the working directory, just as you need to whe calling ShellExecute, although your code does not. Commented Jul 18, 2019 at 22:52

1 Answer 1

0

How I solved my case:

  1. I associated .py files with python.exe in my OS Windows. So, I do not use "python .\PythonDLL_Example.py ....." I use ".\PythonDLL_Example.py ....." instead.
  2. I sorted out, that "%d42" is not an error. This is HINSTANCE of process. I found a mistake of my script (no transmitted arguments to script).
  3. for me, correct is:

    ShellExecuteW(NULL, NULL, "C:\\Users\\Amber\\AppData\\Roaming\\MetaQuotes\\Terminal\\DEA332DEFF5165CB2EAFB6F9BD062C50\\MQL5\\Experts\\Advisors\\PythonDLL_Example.py", "125960 126110 126070 126250 3928 274353.845945816 119761.8349277858 18080.59072693367 -252416.3714632094 -79682.09253258759 -12446.11663140202", NULL, SW_HIDE);
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.