4

I am using the ‘ShellExecute’ function in windows vista

Is there any way to pipe the output to a file?

i.e.

MySqlDump.exe '-u user1 -ppassword dbName > TheOutputFile.Sql

Here my code

theProgram     :=  'MySqlDump.exe';
itsParameters  :=  '-u user1  -ppassword  dbName';
rslt := ShellExecute(0, 'open',
                       pChar (theProgram),
                       pChar (itsParameters),
                       nil,
                       SW_SHOW);

EDIT:

I have tried

 itsParameters  :=  '-u user1  -ppassword  dbName > TheOutputFile.Sql';

but this does not work

Charles Faiga
  • 11,665
  • 25
  • 102
  • 139

4 Answers4

6

@Charles, you can use the redirector simbol ">" in a ShellExecute, but using the cmd.exe which is the Windows command interpreter.

try this sample

ShellExecute(0,nil,'cmd.exe','/c MySqlDump.exe -u user1  -ppassword  dbName > TheOutputFile.Sql',nil,sw_normal);

Another options is use pipes, you can find a very nice example in this link.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
1

In this scenario the simplest approach (barring a cmd script) is probably to use _popen instead of ShellExecute.

Or better yet use the --result-file option to mysqldump.

Logan Capaldo
  • 39,555
  • 5
  • 63
  • 78
1

Cannot vouch for the validity of this code or site, but I've heard of DosCommand.pas more than once. I'll check it tonight when I get home.

Leonardo Herrera
  • 8,388
  • 5
  • 36
  • 66
1

You should start the process using CreateProcess and provide one end of a pipe you create in hStrOutput of the STARTUPINFO structure. There are plenty examples online.

Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67