Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to take the json response from a url and save it to a .json file using curl from the windows command prompt.

My goal is to add a timestamp to the file name.

The following does not work.

curl -k --ntlm -u : --write-out '%{json}' https://myurl.com -o "myfile$(date +"%H:%M").json"

It results in a file like this with no content. enter image description here

The following works fine and produces the expected output, but with no timestamp.

curl -k --ntlm -u : --write-out '%{json}' https://myurl.com -o "myfile.json"

How can I get a .json file with a timestamp?

I've tried both suggestions here and nothing seems to work. enter link description here

question from:https://stackoverflow.com/questions/66050912/curl-command-to-output-filename-with-a-timestamp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
711 views
Welcome To Ask or Share your Answers For Others

1 Answer

This should work:

curl -k --ntlm -u : --write-out '%{json}' https://myurl.com -o "myfile%TIME:~0,2%-%TIME:~3,2%.json"

%TIME% is a Windows built-in dynamic environment variable, and ~0,2 and ~3,2 take hours and minutes substrings from it.

Please note that colon is not allowed in file names in Windows, so I replaced it with a dash.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...