3

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.

4
  • 4
    echo %str% > uptime.txt? Commented Feb 3, 2014 at 11:08
  • Man, I'm sure I tried that!! Do you want to list it as an answer and I'll accept it? Jeeeez i feel dumb now! Thanks! Commented Feb 3, 2014 at 11:29
  • cant you write that output in different file and read new file? Commented Feb 3, 2014 at 12:01
  • 2
    >uptime.txt echo %str% <--- that method eliminates the need for trailing spaces. Commented Feb 3, 2014 at 12:29

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.