![]() |
|
[Shell] Make batch file create another batch file in specific directory - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Shell] Make batch file create another batch file in specific directory (/showthread.php?tid=4714972) |
Make batch file create another batch file in specific directory - ninen2001 - Mar 4, 2015 So I want to make a batch file which creates another batch file with some code in it in a specific folder. How would I do this? * - annikk.exe - Mar 4, 2015 Like this: Code @echo offmd stands for Make Directory. For the part where we create the .bat file, note that the first line uses a single > whereas all subsequent lines use a >> A single > means "Write this text to the file, overwriting the file if it exists" A double >> means "APPEND this text to the file, do not overwrite" Try this code and let me know how you get on. Once you've confirmed you've got it working, we can start to discuss what happens when you try to send reserved characters like the percentage symbol to %out%. :> * - Hash G. - Mar 4, 2015 You will need something like this : Code @echo offAnd you will have a file called yourbatch.bat in the folder C:\Your folder. Explanation : Code @echo off ; I don't need to explain I thinkI hope I have helped ! Edit : I typed too slow :|. Anyway. * - ninen2001 - Mar 4, 2015 (Mar 4, 2015 09:37 AM)Hash G. Wrote: You will need something like this : It created the file where I wanted it to be. But there was no text inside the batch file. The code: @echo off set newBatch="C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\faggotcomet.bat" :calc > %newBatch% start calc.exe > %newBatch% goto :calc > %newBatch% * - FoShizzleMyNizzle - Mar 4, 2015 You need to add some Echos there m8 ;) if you do: Code echo text here WOOOOH > %newbatch%it will be added to your %newbatch% :) And as Annikk just said: For the part where we create the .bat file, note that the first line uses a single > whereas all subsequent lines use a >> A single > means "Write this text to the file, overwriting the file if it exists" A double >> means "APPEND this text to the file, do not overwrite" * - annikk.exe - Mar 4, 2015 Code @echo offTwo things. First of all, you need to echo the commands in order the send them to the batch file. The basic idea here is we use the > symbol to redirect output from the command console to somewhere else, in this case, a file. So normally when we do: Code echo Cats are niceBut if we do: Code echo Cats are nice>cats.txtSo, the first issue is that you need to put an echo command in front of each line of text that you want to send to the file. The second issue is with all the single > symbols. Remember: A single > means "Write this text to the file, overwriting the file if it exists" A double >> means "Write this text to the file, but just add it on as the next line, DO NOT overwrite the existing file" The reason the file appears, but is blank, is because each command overwrites the file with its output. The final command is a "goto" command, which does not have any output, so the file is blank. To fix it, you should always use DOUBLE "greater than" symbols on every line except the first. Code echo Cats are nice>cats.txtWith that in mind, your code should look like this: Code @echo offBy the way, this is an immature script... a batch script trying to be "malicious"... we heavily disapprove of such childishness around here, but I am letting it go for now because you might learn something if you read this far. So I guess it's worth it. * - Nakamoto. - Mar 5, 2015 (Mar 4, 2015 10:27 AM)ninen2001 Wrote: It created the file where I wanted it to be. But there was no text inside the batch file. I wouldn't mind helping you if it were for something productive or useful. I do feel you should be aware that something in the startup folder does NOT make it run on startup. * - ninen2001 - Mar 5, 2015 (Mar 5, 2015 07:25 AM)RenRioku™ Wrote: I wouldn't mind helping you if it were for something productive or useful. I do feel you should be aware that something in the startup folder does NOT make it run on startup. All the files in there does for me. |