ninad
May 23, 2018, 7:56pm
1
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
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:
@Milosz , re JScript, here is an example to test how to pass arguments.
(For the other users: skip all of this if you are not already comfortable with scripting).
(This code, does not do anything useful, It only prints some values using the WScript.Echo function; in Windows, this will open a small popup window with a message. Parsing the parameters and using them in additional code is to be done as needed).
Copy this JScript code in a file that you will save in the AmiBroker's scri…
A proper syntax should look like this:
ShellExecute( "filepath", "arguments", "parameters", showcmd = 1 )
http://www.amibroker.com/guide/afl/shellexecute.html
3 Likes
aron
May 25, 2018, 3:30pm
3
try this:
ShellExecute( "python" , D:/Crypto/test_print.py arg1 arg2 arg3, D:/Crypto/ );
1 Like
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:
when double-clicking on your file, windows needs to know the extension, i.e double-click executes it.
ShellExecute won't wait for your python script to finish, that may or may not be ok
try running the ShellExecute on 1 symbol + 1 bar. Otherwise you execute it many, many times
Cheers.
1 Like
ninad
June 3, 2018, 3:43pm
6
All these solutions work ! This is exactly what I was looking for.
Thanks @Milosz @Dionysos @aron @jamesfisher .
1 Like
ninad
June 3, 2018, 3:49pm
7
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.