tags:

views:

205

answers:

4

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!

+2  A: 

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
SLaks
sorry as i said, i want to use the specific console application i have
DomingoSL
Why? You should be able to do anything using XMLHTTP, and it should be faster.
SLaks
AFAIK, XMLHttp only supports HTTP. Curl can use other protocols.
Mark Bertenshaw
A: 

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.

Bob Riemersma
A: 

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"
Mark Bertenshaw
A: 

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.

wqw