|
Answer» I have a batch file to create a scheduled task on multiple servers. I am trying to set the task RUN: option to call the command and direct output to a logfile. The issue is SCHTASKS interprets the '>' for its role instead of being a member of the string for the /TR switch. My desired result for the tasks RUN: is without brackets ["C:\BigDir\App 2.0\Maintenance\Reboot.cmd" > c:\temp\reboot.log]
Code: [Select]SCHTASKS /Create /S servername /RU account /RP password /SC ONSTART /TN Reboot /TR "C:\BigDir\App 2.0\Maintenance\Reboot.cmd" > c:\temp\reboot.log So you can see that at the '>' character it thinks I want to send the entire line to c:\temp\reboot.log.
I have tried to use the escape character ^> but it does not work either. Am I attempting something that SCHTASKS was never meant to handle?
I tried to pass the > character to a local variable also but cant get that work either, my plan was to then pass the variable to the SCHTASKS /TR and see if I could trick it in there. I set up a test to resemble the purpose I need above.
Code: [Select]@ECHO off SETLOCAL ENABLEEXTENSIONS
set cmdstrg="test test" > test.log
ECHO %cmdstrg% My desired result would be: cmdstrg contains this string without brackets ["test test" > test.log]
Has anyone else found a way around this?
Thanks All!In the interest of keeping it simple, why not substitute the short name (8 dot 3) for your directory: C:\BigDir\App 2.0. The rest of the path has no embedded spaces, so you can use as is.
You can construct of short name path from a dir /x C:\BigDir listing.
Good luck. Hi
This should answer the '>' question.
TYPE %0 | FIND "reboot.log" | FIND /V "FIND" > NEWCMD.CMD GOTO :EOF "C:\BigDir\App 2.0\Maintenance\Reboot.cmd" > c:\temp\reboot.log
I recommend you PASTE the last two lines to the end of your Batch command. GOTO :EOF is to prevent your batch file from trying to execute the command string.
You may copy the first line I gave to any convenient place within your Batch command. This copies the last line as a new creation, NEWCMD.CMD. It does this by typing the entire batch command, and passing the output through FIND to reject any line without the text "reboot.log" - and then it passes through FIND a second time to exclude itself.
The result is a CMD file NEWCMD.CMD, which performs your special command string. If the above does not work with SCHTASKS etc. (of which I know nothing) you MAY need to start the final line with SCHTASKS and all its option switches before the quoted command string.
The above is based on a special DOS trick I invented before there was Windows. It still works on Windows XP - most unusual for Microsoft - every version of Microsoft Excel can create and use macros, but when my Excel spreadsheet was run with a different version of Excel it always found at least one macro to do a different way with the wrong answers !!!
Regards Alan That was very ingenious, ALAN_BR. Thank you Dias, I appreciate that.
If you liked the last one, you may love this one from the same era.
Code: [Select]@echo off IF %1.==. GOTO Z IF NOT %0.==c:\BaT\cD#. c:\BaT\cD# %1 %2 TYPE c:\BaT\cD#.BAT > C:\CD%1.BAT REM TYPE removes any terminating 'Ctrl Z' so destination is appended to "CD " CD >> C:\CD%1.BAT IF NOT %2.==. ECHO %2 >> C:\CD%1.BAT :Z Last line command "CD " has NO CR/LF so above line can append as argument. REM File ends "CD /D " WITHOUT NewLine. Notepad is recommended editor. CD /D Autoexec.bat used to invoke " CDhome " and that immediately switched the DOS shell to the "home" directory and path upon start-up. After Start-up I might move to a different directory and path, and then command " CDhome " would instantly take me back to where I wanted to be. " CD# home " was the magic command to (re)create a new version of CDhome.BAT. " CD# argument " similarly creates CDargument.BAT. " CD_F3 " was what I chose for Drive F:\ and the 3rd most important folder on that drive.
It was especially useful when I had a large set of fixes to implement on a software package. I had a structure C:\Z\Z\Z\Z etc etc with perhaps 100 Z's, and one of those folders would be my latest set of code. At any time I could refer to ..\ for the previous variant, or ..\..\..\..\ to go back 4 versions (actually I used .....\ which OLD DOS realised was the same - pity that NT DOS is not that clever !!!). Relative to my home position, ..\ took me back 1 version, whilst Z\ took me back 99 versions (reuse of a "linear" buffer as a circular buffer). When I finished one of the fixes I could erase files that were 99 versions out of date (i.e. contents of Z\), and copy the latest version to Z\, finally " CD Z " would allow me to easily revert to the "best so far" at ..\ should I make mistakes with the next fix, and " CD# home " would set my new position as my new home. Without CD# I would have had the grief of typing " CD C:\Z\Z\Z\Z\Z etc etc " with exactly the correct quantity of Z's.
My old systems had a path that started with " C:\;C:\BAT\; etc etc " I was not a touch typist, so mostly I worked in "hunt and peck" mode, but I could always find "#" next to the "Enter" key, hence I always used "#" wherever possible, even though it was the first (and only) key that lost its legend. CONSEQUENTLY I actually used "#" wherever the above shows "home", i.e. " CD# # " would create a variant with "home" destination in CD#.BAT in C:\. Consequently the "master" CD#.BAT was put in C:\BAT so that a simple " CD# somewhere " might start with the variant in C:\, BUT that would perform " IF NOT %0.==c:\BaT\cD#. c:\BaT\cD# %1 %2 " so control is switched to the "master", and the variant with the old target destination avoids trying to modify itself (something else that DOS objects to !!!)
The second argument was introduced when I had a computer with multiple drives, and this allowed the command " CD# _F3 F:\ " to append an extra command to CD_F3 to switch drives, so that subsequently " CD_F3 " would not only aim at the chosen path, it would also aim at the chosen drive. This last little kludge is no longer required with NT DOS which now gives CD the /D option, but other commands could be appended - e.g. DIR to remind me what files I have at that path on drive F:\
This batch File has been INVALUABLE to me for over 20 years. I am a little sad that its tremendous "MUST have" value has been diminished by the arrival of NT DOS. Unfortunately progress happens. Can anyone still ride a Penny Farthing bicycle !!!.
Regards Alan
|