views:

252

answers:

4

Hi

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

+1  A: 

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
thanks the --result-file option in mysqldump works well :)
Charles Faiga
+1  A: 

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
+2  A: 

@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
+1  A: 

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