Replacement Commands For Windows 7 (x64)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
pratik151192
Posts: 11
Joined: 25 Sep 2014 23:25

Re: Replacement Commands For Windows 7 (x64)

#16 Post by pratik151192 » 28 Sep 2014 01:09

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 ?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Replacement Commands For Windows 7 (x64)

#17 Post by ShadowThief » 28 Sep 2014 01:12

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.

pratik151192
Posts: 11
Joined: 25 Sep 2014 23:25

Re: Replacement Commands For Windows 7 (x64)

#18 Post by pratik151192 » 28 Sep 2014 01:29

danzas_catreps_dir.log does not contain .txt in that letter case

What does this mean? :|

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Replacement Commands For Windows 7 (x64)

#19 Post by ShadowThief » 28 Sep 2014 01:30

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.

pratik151192
Posts: 11
Joined: 25 Sep 2014 23:25

Re: Replacement Commands For Windows 7 (x64)

#20 Post by pratik151192 » 28 Sep 2014 01:54

Can you please explain as to how this will extract the date from a file through the dir command ?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Replacement Commands For Windows 7 (x64)

#21 Post by ShadowThief » 28 Sep 2014 02:05

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 /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

    Code: Select all

    type %1|find "txt"
    , 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.
  • 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

pratik151192
Posts: 11
Joined: 25 Sep 2014 23:25

Re: Replacement Commands For Windows 7 (x64)

#22 Post by pratik151192 » 28 Sep 2014 02:10

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


??

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Replacement Commands For Windows 7 (x64)

#23 Post by ShadowThief » 28 Sep 2014 02:21

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Replacement Commands For Windows 7 (x64)

#24 Post by foxidrive » 28 Sep 2014 03:33

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.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Replacement Commands For Windows 7 (x64)

#25 Post by Dos_Probie » 28 Sep 2014 04:56

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)

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Replacement Commands For Windows 7 (x64)

#26 Post by ShadowThief » 28 Sep 2014 10:28

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
Last edited by ShadowThief on 29 Sep 2014 16:28, edited 1 time in total.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Replacement Commands For Windows 7 (x64)

#27 Post by ShadowThief » 21 Oct 2014 21:40

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? :oops: )

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"

Post Reply