0

Try to get results from mame64.exe like the -listfull or the -createconfig but in the first ShellExecute command i get result in the second i get nothing

I use this code

begin
  vDir:= 'C:\Emu\Mame\Mame64.exe';
  vDir2:= 'C:\Emu\Mame\gamelist.txt'; 
  ShellExecute(0, nil, 'cmd.exe',PChar('/C '+ vDir +' -listfull > '+ vDir2),nil, SW_HIDE);
  sleep(1000);
  ShellExecute(0, nil, 'cmd.exe',PChar('/C '+ vDir +' -createconfig'),nil, SW_HIDE);
  sleep(1000);
 end;

I can't understand where i have wrong...

azrael11
  • 417
  • 6
  • 18

1 Answers1

3

The mame.ini file will be created in the working directory. You don't specify that, so it is inherited from the calling process. Look for it in the working directory of the calling process, likely the directory where your Delphi executable resides.

Using Sleep isn't a very good idea. Don't use ShellExecute to create the cmd.exe process. Use CreateProcess. Then wait on the returned process handle to be signaled if you need to synchronize. If you wanted to be even more advanced you'd create the mame64 process directly and use an anonymous pipe that you created as its stdout. Then you could avoid having to write any files at all.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thank you David ... How to specify a directory for the output of the mame.ini file? The second part with the pipe sorry i don't understand do you have any direction to look Thank you again – azrael11 Feb 25 '18 at 11:17
  • Well, ShellExecute allows you to specify the working directory in the penultimate argument. CreateProcess also allows that of course. – David Heffernan Feb 25 '18 at 13:00