2010-01-19 26 views
3

我使用的是「的ShellExecute」功能在Windows Vista管道數據與窗口「ShellExecute的」功能的文件

有什麼辦法,以管道輸出到一個文件?

MySqlDump.exe「-u用戶1 -ppassword DBNAME> TheOutputFile.Sql

這裏我的代碼

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

編輯:

我已經試過

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

但這不起作用

回答

4

@Charles,您可以在ShellExecute中使用重定向器simbol「>」,但使用Windows命令解釋程序cmd.exe。

試試這個樣本

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

另一個選項是使用管道,你可以找到在這個link一個非常好的例子。

1

在這種情況下,最簡單的方法(禁止cmd腳本)可能使用_popen而不是ShellExecute。

或更好地使用mysqldump的--result-file選項。

+0

感謝mysqldump中的--result-file選項,效果不錯:) – 2010-01-19 14:17:19

1

無法保證此代碼或網站的有效性,但我多次聽說DosCommand.pas。我回家後會在今晚檢查它。