Solved

Execute cURL command using Visual Basic/vbScript

Posted on 2013-12-10
9
5,071 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
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: 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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help me. 3 55
VB6 ListBox Question 4 44
read an xml file in perl 2 32
Able to retrieve only 1 row through email amongst multiple rows 3 37
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

778 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