简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM