Solved

Execute cURL command using Visual Basic/vbScript

Posted on 2013-12-10
9
5,602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

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!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

734 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