1.

Solve : Generating one batch file from another?

Answer»

Folks,

Sorry for asking the question, as I am sure the answer is out there somewhere - I just don't know the right way to phrase this in a SEARCH:

I would like to run a batch file from a scheduled TASK to create a NEW batch file in the Startup folder and to reboot. The PURPOSE of this is to force an interactive login and action some commands, in a completely hands off fashion.

Because their are several minor variations to the batch files I want to create, I currently have several similar files that I copy to Startup at different times. But this feels untidy. I would rather have the contents of the new files that I want to create stored "in stream" in the main file.

I think that this is possible in Linux Bash script using a "<<<" to an end point, but again, I can't find the details.

Again, sorry for the vague question - flame away one step at a time:

1) create a batch that calls another batch. Get that working and then schedule with the at command.

2) CALL all batch files from a main batch or call the the next batch from the last batch. I believe a main batch offers better control and flow.

C:\>exit /?
Quits the CMD.EXE program (command interpreter) or the current batch
script.

EXIT [/B] [exitCode]

/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE

exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.

C:\>

C:\>type main.bat
Code: [Select]@echo off
call wait1.bat
echo this line will execute when wait1.bat is finished
call wait2.bat
echo this line will execute when wait2.bat is finished
Output:

C:\>main.bat
waitbat1 will sleep 1
this line will execute when wait1.bat is finished
waitbat2 will sleep 2
this line will execute when wait2.bat is finished

C:\>type wait1.bat
Code: [Select]echo waitbat1 will sleep 1

C:\batextra\sleep 1

exit /b
C:\>
C:\>type generatebat.bat
Code: [Select]@echo off

Rem We may generate a new batch file
Rem with redirect (>) and append (>>)


echo echo Hello > newbat.bat
echo date /T >> newbat.bat
echo c:\batextra\sleep 3 >> newbat.bat
echo exit /b >> newbat.bat

C:\>
C:\>type newbat.bat
Code: [Select]echo Hello
date /T
c:\batextra\sleep 3
exit /b
Output:

C:\>newbat.bat

C:\>echo Hello
Hello

C:\>date /T
Tue 09/22/2009

C:\>c:\batextra\sleep 3

C:\>exit /b

C:\>



Discussion

No Comment Found