Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Execute cURL command using Visual Basic/vbScript

Posted on 2013-12-10
9
Medium Priority
?
6,301 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 46

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 46

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 46

Accepted Solution

by:
aikimark earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
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…
Six Sigma Control Plans
Suggested Courses

886 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