|
Answer» Right now I'm just messing around with DOS to try and learn it and I'm trying to make a single script that splits itself into smaller scripts -- one of which I want to write to a text file.
If there's some better way of doing this, please tell me, but in the 'main' program I have it use echo commands with the > sign to store multiple lines to a new, temporary batch file which then runs.
The problem arises when I try a command such as "echo echo TEXT HERE>filename.txt>program.bat" -- I know this command is horribly wrong, however I would assume that someone COULD understand what I'm trying to do with it. Any thoughts?
Also as a side question, is there a list somewhere of all the percent sign variable THINGS like %USERNAME%? And feel free to tell me the proper terms for all this stuff too
Regards Welcome to the CH forums.
Here's a possibility:
Code: [Select]echo off cls
echo Preparing temporary batfile filename.bat echo echo TEXT HERE... > filename.bat echo pause >> filename.bat echo echo Is that what you wanted? >> filename.bat
echo Now running filename.bat
call filename.bat
echo Now back to main batfile.
del filename.bat
%USERNAME% is an environment variable all of which can be viewed by entering SET at the command prompt.
Good luck.
Edit: code edited. Sorry, no cigar
In reference to the code you wrote, my problem is having the main batch file add an echo command to the 'filename.bat' telling it to write to another file.
Basically: The main batch file opens --> the main batch file creates a SECOND batch file --> the second batch file writes to a file
Now to me (and my very little experience with DOS) it seems that the best way to go about doing it is having the main batch file run a command such as what I previously described, something along the lines of "echo echo TEXT HERE>filename.txt>program.bat" -- as I said, this doesn't work, however the 'logical' progression of it would be: The main batch file writes the command "echo TEXT HERE>filename.txt" to program.bat, then when program.bat is run it writes "TEXT HERE" to filename.txt.
Also, the set command worked, ty for that and the welcome.Right!!
The > SYMBOL has special meaning in the Echo command therefore if you want to actually echo the symbol it must be TREATED as a literal rather than a special character. To do this the symbol is Escaped using the caret symbol ^ like this:
Code: [Select]echo off cls
echo echo this is the start ^> filename.txt > filename.bat
call filename.bat
type filename.txt
So the 'main' bat script will create filename.bat which in turn will create filename.txt with the content 'this is the start'
Is that what you want? Yep, that's exactly what I was looking for, ty.
And to think that I was reading through example scripts like that only with the percent sign, and not even connecting the two Yes, well we all had to learn and are still learning. The percent sign is not a special symbol for the Echo command but is for other commands!!
Good luck with your 'messing around'.
D.you can put the codes at the end of your main bat file.
Code: [Select]more /e +1 <"%~f0">another_.bat & exit/b echo off cls
echo echo this is the start ^> filename.txt > filename.bat
call filename.bat
type filename.txt
|