Replacement Commands For Windows 7 (x64)
Moderator: DosItHelp
-
- Posts: 11
- Joined: 25 Sep 2014 23:25
Re: Replacement Commands For Windows 7 (x64)
Can you please throw a little light on why I am getting that error? Is the entire error because of debug.exe ? If it is, then what do you suggest the best alternative for debug.exe would be ?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Replacement Commands For Windows 7 (x64)
foxidrive wrote:danzas_catreps_dir.log does not contain .txt in that letter case
It does on the second line. created.bat is being called, which uses debug. That has to be the source of the problem.
-
- Posts: 11
- Joined: 25 Sep 2014 23:25
Re: Replacement Commands For Windows 7 (x64)
danzas_catreps_dir.log does not contain .txt in that letter case
What does this mean?
What does this mean?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Replacement Commands For Windows 7 (x64)
pratik151192 wrote:Can you please throw a little light on why I am getting that error? Is the entire error because of debug.exe ? If it is, then what do you suggest the best alternative for debug.exe would be ?
Thankfully, whoever wrote created.bat had the good sense to include suggestions for NT-based versions of Windows in the documentation. It looks like the entire purpose of that particular script is to extract a timestamp from the log, create a temporary batch script that sets that value of the fname variable, and then deletes the temp script.
In the example given in the documentation,
TEST BAT 582 04-23-00 11:02p test.bat
would be converted into
set fname=04-23-00
since SQL Server 2008 R2 is NT-based, the dir output now would look something like
04/23/00 11:02 PM 582 test.bat
so you can delete everything from type %1 | find "txt" > ~created.bat through del ~created.bat and replace it with
Code: Select all
for /F "tokens=1,* delims= " %%A in ('type %1 ^| find "txt"') do set fname=%%A
Last edited by ShadowThief on 28 Sep 2014 02:00, edited 1 time in total.
-
- Posts: 11
- Joined: 25 Sep 2014 23:25
Re: Replacement Commands For Windows 7 (x64)
Can you please explain as to how this will extract the date from a file through the dir command ?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Replacement Commands For Windows 7 (x64)
Sure thing. (Also, I needed to update the code because I accidentally left in the test file name I was using instead of %1). In NT-based systems, dir output would look like
04/23/00 11:02 PM 582 test.bat
For more information, see http://ss64.com/nt/for_f.html
04/23/00 11:02 PM 582 test.bat
- for /F allows you to parse strings and split them into tokens
- "tokens=1,*" means when you split the string, store the first token in one variable and the rest of the string in a second variable
- "delims= " means split the string on spaces
- %%A is the variable where the first token is being stored. For tokens increment so the "everything else" variable we specified earlier would be %%B
- in ('type %1 ^| find "txt"') means that the string to be parsed is the output of , where type displays the contents of a text file, %1 is the first parameter passed into the script, | takes the output from type and uses it as the input for find, and find "txt" searches the input for the string "txt" and returns all strings that match. Single quotes are used to allow system commands to be used instead of parsing a string or text file.
Code: Select all
type %1|find "txt"
- do indicates the start of the inside of the loop
- set fname=%%A sets the variable fname to the first token of the input string
For more information, see http://ss64.com/nt/for_f.html
-
- Posts: 11
- Joined: 25 Sep 2014 23:25
Re: Replacement Commands For Windows 7 (x64)
Thanks a hell lot friend. Since I do not have permissions to execute scripts but identify bugs and suggest resolving points, tomorrow, I will update my team and they will try this out. So, for the final conclusion, you said you had to update the code? The replacement for the piece of script that contains the error is :
??
Code: Select all
for /F "tokens=1,* delims= " %%A in ('type %1 ^| find "txt"') do set fname=%%A
??
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Replacement Commands For Windows 7 (x64)
pratik151192 wrote:Thanks a hell lot friend. Since I do not have permissions to execute scripts but identify bugs and suggest resolving points, tomorrow, I will update my team and they will try this out. So, for the final conclusion, you said you had to update the code? The replacement for the piece of script that contains the error is :Code: Select all
for /F "tokens=1,* delims= " %%A in ('type %1 ^| find "txt"') do set fname=%%A
??
Yep, that should be it, unless there's data on the line before the the directory output, in which case it will just grab everything up until the first space on the line.
Re: Replacement Commands For Windows 7 (x64)
pratik151192 wrote:danzas_catreps_dir.log does not contain .txt in that letter case
What does this mean?
If you read the flow of the script in the last log you posted and examine the code, it was how the code got to the end.
It means nothing - because the log showed no error.
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
Re: Replacement Commands For Windows 7 (x64)
Yep, when you upgraded to x64 NT based it looks like you no longer need debug.com or exe since it only works on 32bit as well.
If you have NT, you should learn how to use the
:: switches in the FOR command so you can avoid this!
:: The use of DEBUG to extract data from lines is only
:: needed under Win9x.
http://en.wikipedia.org/wiki/Debug_(command)
If you have NT, you should learn how to use the
:: switches in the FOR command so you can avoid this!
:: The use of DEBUG to extract data from lines is only
:: needed under Win9x.
http://en.wikipedia.org/wiki/Debug_(command)
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Replacement Commands For Windows 7 (x64)
Documented legacy code. With suggestions for enhancements on future systems. Somebody find the guy who wrote that script and buy him a beer.
Update: Never mind, this is just from http://www.ericphelps.com/batch/samples/created.bat.txt
Update: Never mind, this is just from http://www.ericphelps.com/batch/samples/created.bat.txt
Last edited by ShadowThief on 29 Sep 2014 16:28, edited 1 time in total.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Replacement Commands For Windows 7 (x64)
So upon further investigation, it looks like created.bat is actually grabbing the filename and not the timestamp. (You see what happens when I just read the documentation instead of actually looking at the code? )
This changes the code you need to use, unfortunately. This code assumes that the contents of danzas_catreps_dir.log look like
-rw-r----- 1 3050 650 10046 May 21 02:12 catreps/ccN121146.txt
Or, if the lines in danzas_catreps_dir.log look like
-rw-r----- 1 3050 650 10046 May 21 02:12 ccN121146.txt
This changes the code you need to use, unfortunately. This code assumes that the contents of danzas_catreps_dir.log look like
-rw-r----- 1 3050 650 10046 May 21 02:12 catreps/ccN121146.txt
Code: Select all
for /F "tokens=1-11 delims=/. " %%A in ('type %1^|find "txt"') do set "fname=%%J %%K"
Or, if the lines in danzas_catreps_dir.log look like
-rw-r----- 1 3050 650 10046 May 21 02:12 ccN121146.txt
Code: Select all
for /F "tokens=1-10 delims=. " %%A in ('type %1^|find "txt"') do set "fname=%%I %%J"