Page 2 of 2

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 01:09
by pratik151192
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 ?

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 01:12
by ShadowThief
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.

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 01:29
by pratik151192
danzas_catreps_dir.log does not contain .txt in that letter case

What does this mean? :|

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 01:30
by ShadowThief
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

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 01:54
by pratik151192
Can you please explain as to how this will extract the date from a file through the dir command ?

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 02:05
by ShadowThief
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

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 02:10
by pratik151192
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


??

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 02:21
by ShadowThief
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)

Posted: 28 Sep 2014 03:33
by foxidrive
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.

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 04:56
by Dos_Probie
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)

Re: Replacement Commands For Windows 7 (x64)

Posted: 28 Sep 2014 10:28
by ShadowThief
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

Re: Replacement Commands For Windows 7 (x64)

Posted: 21 Oct 2014 21:40
by ShadowThief
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"