Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the curl command in PowerShell?

Am using the curl command in PowerShell to post the comment in bit-bucket pull request page through a Jenkins job. I used the below PowerShell command to execute the curl command, but am getting the error mentioned below. Could anyone please help me on this to get it worked?

$CurlArgument="-u [email protected]:yyyy -X POST https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments --data content=success" $CURLEXE='C:\Program Files\Git\mingw64\bin\curl.exe' & $CURLEXE $CurlArgument 

Error Details:

curl.exe : curl: no URL specified! At line:3 char:1 + & $CURLEXE $CurlArgument + ~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (curl: no URL specified!:String) [], RemoteException     + FullyQualifiedErrorId : NativeCommandError  curl: try 'curl --help' or 'curl --manual' for more information
like image 510
VADIVEL NATARAJAN user2505309 Avatar asked Oct 18 '16 10:10

VADIVEL NATARAJAN user2505309


People also ask

How do I use the curl command in PowerShell?

The conclusion is that if you need to use the curl (as same as in the Windows command prompt) in PowerShell then you need to call the curl executable( curl.exe ) directly. Else, you should stick to the PowerShell curl alias which resolves to the Invoke-WebRequest cmdlet under the hood.

Can I run curl from PowerShell?

curl requires minimal user interaction and is therefore preferred for automation. curl in PowerShell uses Invoke-WebRequest . From PowerShell 3.0 and above, you can use Invoke-WebRequest , which is equivalent to curl .

Is curl installed in PowerShell?

cURL comes natively installed on Unix based operating systems such as MacOS and Linux. But windows is left out. Now that we have PowerShell on windows, you can get some of the functionality of cURL using various cmdlets like invoke-webrequest.

How do I run a curl command in Windows?

crt . Invoke curl.exe from a command window (in Windows, click Start > Run and then enter "cmd" in the Run dialog box). You can enter curl --help to see a list of cURL commands.


1 Answers

Use splatting.

$CurlArgument = '-u', '[email protected]:yyyy',                 '-X', 'POST',                 'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',                 '--data', 'content=success' $CURLEXE = 'C:\Program Files\Git\mingw64\bin\curl.exe' & $CURLEXE @CurlArgument 
like image 62
Ansgar Wiechers Avatar answered Oct 05 '22 20:10

Ansgar Wiechers