0

I want to run CMD from vb.net and then run a curl command with it. I have followed the options in this question How to run DOS/CMD/Command Prompt commands from VB.NET? already but it doesn't work for me.

I am running this command via vb.net.

Process.Start("cmd /k", "curl --location --request GET http://ipaddress:port/")

The expected output should be Hello-World. But I get an error that "

System can not find the file specified.

However when I am running the same command in CMD then it works fine. Is there any way to make it work?

I have seen the other methods like httpwebrequest and already tried them and it works but I do not want to use those methods as I have many other complex curl commands and do not want to convert them to lengthy httprequests.

Please guide me with the explained problem.

Thank you in advance.

Best Regards

SAIP
  • 99
  • 7

1 Answers1

3

When you run curl within your command prompt, what this does behind the scenes is prefix the respective environment variable for you. You can verify this by doing the following:

  1. Use the Shortcut Key Windows Key + s to bring up the search box
  2. Type in Environment Variables and pick the top result
  3. Click on the Environment Variables button towards the bottom
  4. Inspect the Path (or PATH) variable for where your curl.exe application lives

For my operating system, the application lives at C:\Windows\System32\curl.exe.

Once you get the fully qualified filename, there is one other error in your code. You are attempting to pass the /k in the filename argument of Process.Start. Instead, pass it in the arguments argument.

Here is an example:

Dim curlApplicationPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "curl.exe")
Dim arguments = $"/k {curlApplicationPath} --location --request GET http://ipaddress:port/"
Process.Start("cmd", arguments)
David
  • 5,877
  • 3
  • 23
  • 40