使用 Windows“ShellExecute”将数据通过管道传输到文件功能

发布于 2024-08-18 00:41:35 字数 625 浏览 3 评论 0原文

我在 windows vista 中使用“ShellExecute”函数

有什么方法可以将输出通过管道传送到文件吗?

MySqlDump.exe'-u user1 -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';

,但这不起作用

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深居我梦 2024-08-25 00:41:35

@Charles,您可以使用重定向器符号“>”在 ShellExecute 中,但使用 Windows 命令解释器 cmd.exe。

尝试这个示例

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

另一个选项是使用管道,您可以在此链接中找到一个非常好的示例。

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

找回味觉 2024-08-25 00:41:35

在这种情况下,最简单的方法(禁止 cmd 脚本)可能是使用 _popen 而不是 ShellExecute。

或者更好的是使用 mysqldump 的 --result-file 选项。

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.

久伴你 2024-08-25 00:41:35

无法保证此代码或网站的有效性,但我听说过 DosCommand .pas 不止一次。今晚我回家后会检查一下。

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.

此生挚爱伱 2024-08-25 00:41:35

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文