从 Visual Basic 6 向控制台程序发送命令

发布于 2024-08-30 02:20:33 字数 242 浏览 4 评论 0原文

我在windows上有一个控制台程序curl命令行的编译版本),您可以在其中编写命令并返回。我怎样才能发送命令到这个控制台应用程序并将结果返回到VB6?我知道您可以通过 Windows Script Host 使用 DOS 命令来执行此操作,但正如您所看到的,我要运行的命令不在 command.exe 中,

谢谢!

I have a console program on windows (a compiled version of curl command line) in where you can write commands and have a return. How can i send commands to this console application and return the result to VB6? I know you can do this with DOS commands with Windows Script Host but as you see the commands i want to run dont are in command.exe

Thanks!

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

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

发布评论

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

评论(4

摘星┃星的人 2024-09-06 02:20:33

您可以使用 Microsoft.XMLHTTP ActiveX 对象发出 HTTP 请求,如下所示:

Set request = CreateObject("Microsoft.XMLHTTP")
request.open "POST", url, false
request.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
request.send postData
response = request.responseText

You can use the Microsoft.XMLHTTP ActiveX object to make HTTP requests, like this:

Set request = CreateObject("Microsoft.XMLHTTP")
request.open "POST", url, false
request.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
request.send postData
response = request.responseText
最好是你 2024-09-06 02:20:33

Domingo -

嗯,我假设既然您提到了它,您就知道如何使用 WSH 库。您需要的唯一其他信息是执行所需命令的字符串。您可以在 Windows 95/98/Me 中使用此字符串运行 DOS 命令:

Dim sMyCommandLine As String

sMyCommandLine = "command.exe /c MYCOMMAND"

但是,您似乎更有可能使用基于 NT 的操作系统,例如 Windows NT、2000、XP、Vista 或 7,在这种情况下,您应该使用:

sMyCommandLine = "cmd.exe /c MYCOMMAND"

Domingo -

Well, I am assuming that since you mentioned it, you know how to use the WSH library. The only other piece of information you need is the string to execute the command you want. You can run DOS commands with this string in Windows 95/98/Me:

Dim sMyCommandLine As String

sMyCommandLine = "command.exe /c MYCOMMAND"

However, it seems more likely that you would be using an NT based operating system such as Windows NT, 2000, XP, Vista or 7, in which case, you should use:

sMyCommandLine = "cmd.exe /c MYCOMMAND"
梦屿孤独相伴 2024-09-06 02:20:33

您应该能够将这个curl 东西作为子进程运行,将其标准I/O 流重定向到匿名管道。然而,VB6 中没有任何东西可以直接支持这一点。

一种方法是通过添加对 Windows 脚本宿主对象模型的引用来使用与 WSH 脚本中相同的内容。另一种不产生控制台窗口的更简洁的方法涉及大量 API 调用来创建子进程、管理子进程以及在 VB6 程序中读/写匿名管道。如果您还没有创建用于执行此操作的组件,那么这将是更多工作。

You should be able to run this curl thing as a child process, redirecting its standard I/O streams to anonymous pipes. However there is nothing in VB6 to support this directly.

One way is to use the same things you would in a WSH script by adding a reference to Windows Script Host Object Model. Another cleaner approach which does not produce a console window involves a number of API calls to create the child process, manage it, and read/write the anonymous pipes in your VB6 program. This is more work if you haven't created a component for doing it already.

我也只是我 2024-09-06 02:20:33

您可以使用Shell函数来启动控制台应用程序,但它不会返回子进程的结果——即批处理脚本中所谓的Errorlevel

要阻止替换 Shell,您可以 查看此处发布的 ShellWait 函数

You can use the Shell function to start the console application but it will not return the result from the child process -- the so called Errorlevel in batch scripts.

For a blocking replacement of Shell you can check out ShellWait function posted here.

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