Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use '&' as an argument in windows commandline

I’ve written a nodejs package that allows you to make HTTP(S) requests from the Windows terminal, so you type in something like http get https://stackoverflow.com and bam, there’s the response. Something I’ve noticed, however, is that using an ampersand (&) in a URL breaks the command. It seems like this is a feature built in to let you run multiple commands in one line. So if you run:
http get https://api.example.com/getinfo?request=example&apikey=APIKEY, then it makes a request to https://api.example.com/getinfo?request=example, and then tries to run ‘apikey’ as a command, yielding the error: 'apikey' is not recognized as an internal or external command, operable program or batch file.
Is there a way I can get around this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I don’t know if this works on Windows as well, but on Linux you can put a string in single or double quotes. Then the string is given to the application without being interpreted by the terminal (except for replacing environment variables with $ in double-quotes). This is also useful if you want to pass an argument with whitespaces.

So, try

http get "https://api.example.com/getinfo?request=example&apikey=APIKEY"

or

http get 'https://api.example.com/getinfo?request=example&apikey=APIKEY'

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading