Solved

Execute cURL command using Visual Basic/vbScript

Posted on 2013-12-10
9
4,895 Views
Last Modified: 2013-12-11
Hello,

Can someone help me understand how to execute a cURL command using a Visual Basic code/vbScript? Basically, I am trying to develop a gui to execute some repetitive tasks in DataPower using SOMA scripts. In short, a cURL command to execute a SOMA script would look like this:

curl --insecure -u bji:datapower00 --data-binary @'C:\cygwin64\bin\AMP_getdomainlist.xml' https://24.172.189.104:4440/service/mgmt/amp/1.0

Right now, I am using Cygwin (UNIX simulator for Windows) to execute that command.

Thanks!
Jay
0
Comment
Question by:Jammerules
  • 5
  • 3
9 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 39710437
Is CURL in the path?  If so, you can Shell it from the VBA environment or use a wscript.shell object's RUN() method.

If you open a command prompt window, can you type that CURL command as you've written it an it will run, or do you need to change to a different drive or directory first?  If the command will run anywhere, you might use a tweaked version of my first comment, by prefacing the CURL command with a "cmd /c " string.
0
 

Author Comment

by:Jammerules
ID: 39710457
Here is the piece of code I came up with. For some reason when I execute it, I am unable to output into a local file.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
 
Public Function RunCMD(ByVal FileName As String) As String
   RunCMD = ShellExecute(0, "open", FileName, "", "", 1)
End Function
''
Private Sub cmdSubmit_Click()
Dim fname As String
fname = "c:\temp\Test.bat"
RunCMD fname
DoEvents
MsgBox "Done"
End
End Sub

Open in new window


On the other hand, if I just double clicked the Test.bat file, the result is outputted to a file. Here is the cURL command that I am using:
curl --insecure -u usrnm:pwd --data-binary @"C:\SOMA Scripts\getLogs.xml" https://24.172.189.99:4440/service/mgmt/2004 -o cURLOutputfile.txt 

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 39711339
1. have you done a file search on your hard drive for cURLOutputfile.txt?
2. I'm concerned about the END statement on line 13.  Why is it there?

Your batch file does not set a drive or directory prior to executing the CURL command. The output file will go to the default directory, usually c:\users\yourlogin\
0
 

Author Comment

by:Jammerules
ID: 39711640
1. I did search for the output file and to no avail.
2. The END is there to kill the program execution. I tried executing  without it and it still behaves the same way.

See attached picture for better understanding. I had to mask to user name and password after "-u"
Output.jpg
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Jammerules
ID: 39711644
... by prefacing the CURL command with a "cmd /c " string.

Can you elaborate on this?
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 39711707
I noticed two things:
1. the current directory is not the default directory
2. one of these two commands did not work
0
 

Author Comment

by:Jammerules
ID: 39712061
The difference I see between running the bat file via VB and stand alone is that, when I run from VB, the command prompt looks like this:

C:\Program Files (x86)\Microsoft Visual Studio\VB98

whereas running stand alone looks like:

C:\temp\

I have installed cURL files in VB98 separately. How can I make my vb code to cURL from the default Windows path?
Output.jpg
0
 

Author Comment

by:Jammerules
ID: 39712185
Success!

So, this is what I did.

1. First I made an "exe" of the program.
2. Next, I copied all the cURL.exe and its dlls to the same folder where I have my Visual Basic exe

That fixed it! :)

Thanks for your responses though.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
This article will show, step by step, how to integrate R code into a R Sweave document
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now