-
Play videoPlease edit your post.
For large amounts of code, attach it.
- Your shell call specifies c.bat, but that is not an executable file, so it fails. Try:// int r = ShellExecuteW(0,"Open","C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D42A6903521AA0A52E40B0910C7C2934\MQL4\Files\c.bat",NULL,NULL,5);
int r = ShellExecuteW(0,"Open","cmd.exe","/C C:\\Users\\Partha\\AppData\\Roaming\\MetaQuotes\\Terminal\\D42A6903521AA0A52E40B0910C7C2934\\MQL4\\Files\\c.bat",NULL,5);
Partha:
int r = ShellExecuteW(0,"Open","C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D42A6903521AA0A52E40B0910C7C2934\MQL4\Files\c.bat",NULL,NULL,5);
Escape all the back slashes.
Ovo: Escape all the back slashes.
| That also |
Thanx WHRoeder and Ovo for the valuable inputs. After quite a bit of trial and errors, It's working now. For benefit of other users, here's the complete code:
#include <WinUser32.mqh> #import "shell32.dll" int ShellExecuteW(int hwnd,const string Operation,const string File,const string Parameters,const string Directory,int ShowCmd); #import void OnInit() { string terminalDataPath=TerminalInfoString(TERMINAL_DATA_PATH); int r = ShellExecuteW(0,"Open","c.bat",NULL,terminalDataPath,5); Print("Shell ",r); }
c.bat (located in "C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D42A6903521AA0A52E40B0910C7C2934" folder):
@echo off copy C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D42A6903521AA0A52E40B0910C7C2934\MQL4\Files\TradeCopy.csv C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D22174118A10226954F7121FC08B77A4\MQL4\Files /y > copy.txt
Also, need to make sure that DLL imports are enabled in MT4.
One more thing. Alternatively cmd.exe may also be used. So the statement would be like:
int r = ShellExecuteW(0,"Open","cmd.exe","/C c.bat",terminalDataPath,5)
Thanks Partha for sharing.. This code works great. God bless all..
Yes, this code works for me too. Thanks a lot.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I am trying to run a batch file from EA, but it's not working. The full text is inserted below. Can anybody help? Appreciate a direct ans i/o link to another forum
#include <stdlib.mqh>
#include <WinUser32.mqh>
#import "shell32.dll"
int ShellExecuteW(int hwnd,const string Operation,const string File,const string Parameters,const string Directory,int ShowCmd);
#import
void OnInit()
{
}
void Start()
{
int r = ShellExecuteW(0,"Open","C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D42A6903521AA0A52E40B0910C7C2934\MQL4\Files\c.bat",NULL,NULL,5);
Print("Shell",r);
}
c.bat:
@echo off
copy C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D42A6903521AA0A52E40B0910C7C2934\MQL4\Files\TradeCopy.csv C:\Users\Partha\AppData\Roaming\MetaQuotes\Terminal\D22174118A10226954F7121FC08B77A4\MQL4\Files /y > copy.txt