Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

saving string value to a file

I want to save string variable from .cmd to external file. Just to append it not overwrite it. Something like this

current date/time     string value

Is it possible?
0
axcx
Asked:
axcx
2 Solutions
 
oBdACommented:
Just use the "double" redirection, which will append instead of overwrite: ">>". You can add it before or after the echo ..." command, but I prefer it in front so there are no trailing spaces or the need for brackets:
>>"C:\Temp\echo_date.txt" echo current date/time: %Date% %Time%

Open in new window

or (with a trailing space at the end of the line):
echo current date/time: %Date% %Time% >>"C:\Temp\echo_date.txt"

Open in new window

or (no trailing space, but with brackets)
(echo current date/time: %Date% %Time%)>>"C:\Temp\echo_date.txt"

Open in new window

0
 
dlb6597Commented:
echo %time% %string% >>output.txt

where %string% is your variable, output.txt is the file you wish to append to.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now