0

Heroku has this nice command which allows me to use curl to download a file which works fine in UNIX:

curl -o latest.dump `heroku pgbackups:url`

The command in backticks yields a very long URL that is difficult to copy/paste into my Windows CMD console.

Since backticks don't seem to work in Windows, what is the equivalent in Windows? My research on CMD went into deep dives into creating a batch file which I think is overkill for this small purpose. Googling curl's man pages yielded nothing that popped out. Googling around for other resources seem to indicate generating a POST request, which I don't think this is.

What's the equivalent command in Windows CMD? thanx, sam

  • Windows' CMD.EXE is not a real grown-up shell. I recommend you install cygwin and work with BASH under Windows. – Eugen Rieck Jul 1 '14 at 16:31
  • See "Batch Files - How to set commands output as a variable" on Stack Overflow. – Cristian Ciupitu Jul 1 '14 at 16:49
  • According to blogs.msdn.com/b/oldnewthing/archive/2012/07/31/10334556.aspx "The Windows command processor does not have direct backquoting, but you can fake it by abusing the FOR command"... see also above comment. – mpy Jul 1 '14 at 16:54
  • In cygwin => curl -o latest.dump heroku.bat pgbackups:url => appears that curl is working but the % Received is all zeroes across the board. As opposed to Terminal in the Mac. I don't see why that would happen in cygwin. – sam452 Jul 1 '14 at 17:34
  • Reading the SO post, it's not clear how this relates to my command. It appears that this is going to be a .BAT file with some arguments passed to it, because I see the %%. But it's not clear to me how a BAT file would interact with this command. – sam452 Jul 1 '14 at 17:47
1

This is no original research, but borrowed from MSDN Blogs. There it is stated that

There is no obvious way to read the output of a command into a (...) variable. In unix-style shells, this is done via backquoting. (...) The Windows command processor does not have direct backquoting, but you can fake it by abusing the FOR command.

And here is an example with such a for command, resembling unix's echo `your_command`:

for /f "delims=" %i in ('your_command') do @echo "%i"
  • /f activates the following syntax (see help for for more info):

    FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
    
  • delim= disables the splitting at white spaces

  • @echo prints the content of the variable %i, but the echo call itself is suppressed (@)
0

As @Eugen Rieck already stated, I suggest you use a proper terminal too. But regarding your question:

  • The backticks are used to execute something and using its result inline, they evaluate a command:

    echo `date`
    

    Or

    echo $(date)
    

    Will print:

    mar jul  1 11:46:42 CDT 2014
    

    So in your case it's trying to execute heroku command with pgbackups:url as a parameter. You can refer to this question: Batch Files - How to set commands output as a variable as Christian suggests on the comments.

  • And to pass a parameter to a GET request you should simply append said params to the URL, for instace, if you want to pass a variable named number with the number 10 and a variable named text that holds "I'm a text", your URL should look like this:

    "http://example.com/script.php?number=10&text=I'm+a+text"
    
  • This is excellent background, thank you. The link presented is fine but lacked additional info that the other link provided. That other link worked for me. – sam452 Jul 1 '14 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.