How to get cmd.exe response as string in mql5?

To add comments, please log in or register
Yashar Safarzadeh
384
Yashar Safarzadeh  

Dear All

I want to get cmd.exe response to get some machine id from it and using in my mql5 code

#import "shell32.dll" 
int ShellExecuteW(int hwnd,string operation,string file,string parameters,string directory,int showCmd); 
#import

void OnStart()
  {
string strParameters = "wmic csproduct get uuid";
int result = ShellExecuteW(0, "open", "cmd.exe", strParameters, NULL, 1);
if (result <= 32) Print("Shell Execute Failed: ", result); 
Print(result);
  }

But I couldn't find how to get the cmd response to following line in an string variable.

wmic csproduct get uuid

please help me.

Keith Watford
Moderator
25628
Keith Watford  
Yashar Safarzadeh:

I want to get cmd.exe response to get some machine id from it and using in my mql5 code

Why have you posted in the MQL4 section.

I will move your post to General.

Yashar Safarzadeh
384
Yashar Safarzadeh  
Keith Watford:

Why have you posted in the MQL4 section.

I will move your post to General.

Yes,I did mistake, move it please.
William Roeder
23285
William Roeder  
Yashar Safarzadeh: But I couldn't find how to get the cmd response to following line in an string variable. 

Direct the output to a file, read the file.

Yashar Safarzadeh
384
Yashar Safarzadeh  
William Roeder:

Direct the output to a file, read the file.

But "ShellExecuteW " doesn't provide any output in text file. How can I output cmd results in an text file?
William Roeder
23285
William Roeder  
The command you call must redirect.
Yashar Safarzadeh
384
Yashar Safarzadeh  

William Roeder:
The command you call must redirect.

I used following code to output the text file. But nothing was produced.

 string strParameters = "wmic csproduct get uuid >> myoutput.txt";
   int result = ShellExecuteW(0, "open", "cmd.exe", strParameters, NULL, 0);
   if (result <= 32) Print("Shell Execute Failed: ", result);
   Print(result);

While running following command produces the output file.

"wmic csproduct get uuid >> myoutput.txt"
Printing Error gets value 42.
Yashar Safarzadeh
384
Yashar Safarzadeh  

Dear William

Thanks for your guide. I solved the problem by running from a batch file and putting the files to Terminal Files folder.

To add comments, please log in or register