Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionI'm working on a school project, and I'm trying to figure out how to use a variable, output, to output to an existing text file called output.txt. Currently I am not having much luck as it either gives me a syntax error, or it just won't output the results from that command when using that variable. Basically I am trying to map the command to output the data to the existing text file, or at least the path to the text file, including the file name, to the variable. Could anyone explain to me how to do this?
Thanks, Peter
Your description is very unclear, but if I understand you correctly you want something simple like echo:
set output=variable you got from somewhere, just using set here as a example
echo %output% > output.txt
(Change > to >> if you want to append data and not overwrite the existing data)
Currently I've tried the following: set /p output = < output.txt
set output =>> output.txt
set output = >> output.txt
and set output = ">> output.txt"
, however none of them seem to be working.
Try escaping your carats:
set output = ^>^> output.txt
echo "string to write to file with quotes" %output%
I've found the issue I was encountering. Apparently windows bat files will toss errors if you try to put a file name in the variable. This means that my intended solution is moot point.
精彩评论