开发者

Piping data to a file with the windows ‘ShellExecute’ function

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, 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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜