Delphi 7:如何执行shell命令并检查结果? [英] Delphi 7: how to execute shell command and check the result?

查看:136
本文介绍了Delphi 7:如何执行shell命令并检查结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Delphi 7,无法预测目标版本的Windows。



我需要创建一个数据库(可能是MySql,但可能还有其他的东西) )并定义一些表结构。我不需要填写任何数据。不幸的是,所有的ADO组件似乎都期望一个数据库已经存在,然后他们将允许你操纵它。



所以,由于这只是一些简单的命令,我以为我可以使用ShellExectute()。



同意?不同意?



任何人都可以给我一个示例代码,将尝试运行MySql --version,让我检查结果?之后,我应该能够为自己弄清楚。谢谢。








但我知道如何google。只是我没有找到有用的结果。这是我自己的错,在这个问题上不明确,所以请接受我的道歉 - 我需要的是代码示例,而不仅仅是组件的名称。



对不起(谢谢你迄今为止的回复(所有这些都是+1))








Robert给出的链接(程序RunDosInMemo()执行的技巧)... 但是你必须记住要包含一个.exe扩展名(so ,'notepad.exe',而不仅仅是'记事本',如果您的命令不在路径上,请填写完整路径。

解决方案

这是一篇文章,详细解释了



从DOS(命令/控制台)窗口捕获输出



但简而言之,您需要创建两个管道来读取和写输出,然后您需要在 TStartUpInfo结构,然后将此结构传递给 CreateProcess()调用。



这里是另一篇文章,显示如何等待流程完成。


I'm using Delphi 7 and can't predict the target version of Windows.

I need to create a database (probably MySql, but might be something else) and define some table structures. I do not need to populate any data. Unfortunately, all of the ADO components seem to expect that a database already exists and they will then allow you to manipulate it.

So, since it's only a few simple commands, I thought that I might as well use ShellExectute().

Agree? Disagree?

Can anyone give me a sample code which will attempt to run "MySql --version" and let me check the result? After that I should be able to figure it out for myself. Thanks.


[edit]

No offence intended, but I do know how to google. It's just that I don't find useful results. It's my own fault for not being explicit in this question, so please accept my apology - what I need is a code example, not just the name of a component.

Sorry (and thanks for the replies so far (all of which are +1))


[edit]

The links which Robert gives do the job (procedure RunDosInMemo() does the trick) ... B U T you Must remember to include an .exe extension (so, 'notepad.exe', not just 'notepad', and to ge a full path if your command is not on the path.

解决方案

Here is an article that explains it detail

Capture the output from a DOS (command/console) Window

But in short you need to Create two pipes to read and write the output. Then you need to set StdInput and StdOutput in the TStartUpInfo structure, then pass this structure to the CreateProcess() call.

Here is another article that shows how to Wait for the process to finish.

这篇关于Delphi 7:如何执行shell命令并检查结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆