Can we run a python script using ShellExecute()?

My aim is to pass arguments to a python script just like we do in cmd by running the following command
python test_print.py arg1 arg2 arg3

I have added a line
ShellExecute( "python", "", "D:/Crypto/test_print.py");

It opens a python shell as follows python

my test_print.py is as follows (not passing the args for now as the script is not getting executed ),

value=2
while(1):
	print value

I would appreciate any help.

@ninad I may be wrong, but I think you are making a mistake in using ShellExecute(). Look at this example of passing arguments to external file. Pay attention to the syntax:

A proper syntax should look like this:

ShellExecute( "filepath", "arguments", "parameters", showcmd = 1 ) 

http://www.amibroker.com/guide/afl/shellexecute.html

3 Likes

try this:

ShellExecute( "python" , D:/Crypto/test_print.py arg1 arg2 arg3, D:/Crypto/ );
1 Like

There is a description how to run ".bat"
https://automatetheboringstuff.com/appendixb/

This one works:
Had looked for a solution myself.

ShellExecute("C:\\Program Files\\AmiBroker\\YOURPYTHONFILE_v1.py","","",0);

the "0" at the end prevents the cmd prompt from popping up.
Take note:

  1. when double-clicking on your file, windows needs to know the extension, i.e double-click executes it.
  2. ShellExecute won't wait for your python script to finish, that may or may not be ok
  3. try running the ShellExecute on 1 symbol + 1 bar. Otherwise you execute it many, many times

Cheers.

1 Like

All these solutions work ! :smiley: This is exactly what I was looking for.
Thanks @Milosz @Dionysos @aron @jamesfisher . :heart:

1 Like

I did not understand exactly what did you mean by this.
I want to call this script every time I get a buy/sell signal only. I'll see how it can be done.

if you run the ShellExecute in your .afl for say backtesting, and in your database are 100 symbols, that means you execute the ShellExecute 100 times.
(provided there are not conditional "ShellExecutes")

Of course it depends on what you are trying to achieve... yet worth mentioning.