Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute program with output redirection from Inno Setup

I am trying to make a database backup on uninstall but for some reason program with redirection always fails in Inno Setup. Here is what I have:

[Run]
Filename: "{#DB_PATH}\mysqldump.exe"; \
  Parameters: "-c --compact {#DB_NAME} > {#STORAGE_PATH}\db.sql";  Flags: runhidden;
Filename: "xcopy";                     \
  Parameters: "{#STORAGE_PATH} {userdesktop}\Backup\ /E/H"; Flags: runhidden;
Filename: "{#DB_PATH}\mysqladmin.exe"; \
  Parameters: "shutdown"; Flags: runhidden;

The last two commands works correctly. But the first one never works for some reason. I've already tested the command and it works without any issues.

I am not sure if am doing something wrong so any help is appreciated.

like image 546
ctf0 Avatar asked Jun 04 '26 08:06

ctf0


1 Answers

This seems to be a variation of:
How does output redirection work in Inno Setup?

With small difference, that you are using [Run] section and not Pascal Script code.

The output redirection syntax is a feature of the command prompt, not the core Windows APIs. Therefore if you want to redirect output then you need to invoke the command via {cmd} /c actual-command-line > output-file.

So it should be:

Filename: "{cmd}"; \
  Parameters: "/C {#DB_PATH}\mysqldump.exe -c --compact {#DB_NAME} > {#STORAGE_PATH}\db.sql"; \
  Flags: runhidden;

But you should quote all paths as well (and due to obscure syntax that cmd.exe uses, you then need to quote whole command as well):

Filename: "{cmd}"; \
  Parameters: "/C """"{#DB_PATH}\mysqldump.exe"" -c --compact {#DB_NAME} > ""{#STORAGE_PATH}\db.sql"""""; \
  Flags: runhidden;
like image 92
Martin Prikryl Avatar answered Jun 06 '26 07:06

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!