Write command line variable into text file

I've got as far as I can with this one, but struggling at the last hurdle.

I am attempting to get the uptime of my Windows 7 machine, load it into a variable, trim the current time from the left part of the variable and then write it back from a variable into a .txt file.

All works just fine, except I do not know how to write the variable back into a text file.

Here is what I have:

c:
cd/
uptime.exe > uptime.txt
set /p str=<uptime.txt
echo.%str%
set str=%str:~-16%
echo.%str%

Now the last echo line displays exactly what I want, but how do I write that variable back into uptime.txt?

Thanks in advance for any assistance.

Answers


You can simply redirect standard output to the file of your choice to achieve your goal. For example:

echo %<name of environment variable>% > <path of file>
echo %str% > uptime.txt

Need Your Help

How to play a fullscreen video on click ? (AngularJS)

javascript html angularjs video fullscreen

I've an image with a fake play button on it and I would want to open a fullscreen video on play click button.

Is packet duration guaranteed to be uniform for entire stream?

ffmpeg seek libavformat pts

I use packet duration to translate from frame index to pts and back, and I'd like to be sure that this is a reliable method of doing so.