Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Windos XP batch file query
PostPosted: Thu Nov 29, 2012 12:41 
User avatar
Isn't that lovely?

Joined: 30th Mar, 2008
Posts: 11168
Location: Devon
Strange issue with batch files (Windows XP)

I have 3 batch files

The first one does this:

Code:
   SETLOCAL EnableDelayedExpansion
   set count=1
   md fix
   copy *.corrupt fix
   cd fix
   
   FOR /F "tokens=1 delims=" %%A IN ('dir /b') DO (
         SET infile=original!count!
         echo !infile!
         rename %%A !infile!
         call log !infile!      
         SET /A COUNT=!COUNT!+1
      )



Where log is the name of the 2nd batch file. which looks something like this:

Code:
   set clp1=%1
   IF NOT "%clp1%"== "" (set file1=%clp1%) else (set file1=original)
   set file2=%file1%.one.txt
   set file3=%file1%.two.txt
   set file4=%file1%.three.txt
   echo Original:   %file1%
   echo Log File:      %file2%
   echo Details:      %file3%
   echo One Line:      %file4%
   external1 %file1% 2>%file2% 1>>&2
   echo. >>%file2%
   external2 %file1% >>%file2%
   external3 %file1% >>%file4%
   call out %file1%
   start %file1%
   start %file2%
   start %file3%


Out is the name of the 3rd of batch file, which does a whole load of stuff.

As you have probably worked out, the first batch file is just a tool to copy a whole load of corrupt files to a folder called fix, which it creates, then it calls the log batch file which runs 3 commands to generate some log files, this then calls the 3rd batch file which process one of the log files to create another file.

Now, the problem When these batch files finish running, I am left in the root folder, not the fix folder. I can see from the output window, when it runs the start lines, it is in the fix folder.

Why does it return to the root folder? I don't have a line that does cd.. or anything like that, and it never used to (I modified the first batch file to handle more than file (the whole For /F bit, before that it just had the "call log original" line (with a line to rename *.corrupt to original)

Any one have any ideas?

Malc

_________________
Where's the Kaboom? I was expecting an Earth shattering Kaboom!


Top
 Profile  
 
 Post subject: Re: Windos XP batch file query
PostPosted: Thu Nov 29, 2012 12:45 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12334
Is it because you don't cd to the fix directory in the second file?

Can you just add a manual cd in to where it is kicking you to root?

Disclaimer: I am not any good at this.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Windos XP batch file query
PostPosted: Thu Nov 29, 2012 12:49 
User avatar
Isn't that lovely?

Joined: 30th Mar, 2008
Posts: 11168
Location: Devon
Mr Russell wrote:
Is it because you don't cd to the fix directory in the second file?

Can you just add a manual cd in to where it is kicking you to root?

Disclaimer: I am not any good at this.


I could do, but I want to understand why I need to

Malc

_________________
Where's the Kaboom? I was expecting an Earth shattering Kaboom!


Top
 Profile  
 
 Post subject: Re: Windos XP batch file query
PostPosted: Thu Nov 29, 2012 13:18 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12334
Malc wrote:
Mr Russell wrote:
Is it because you don't cd to the fix directory in the second file?

Can you just add a manual cd in to where it is kicking you to root?

Disclaimer: I am not any good at this.


I could do, but I want to understand why I need to

Malc


As I say, my guess is because the second batch file starts from root and has no cd in it to say where to start from.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Windos XP batch file query
PostPosted: Thu Nov 29, 2012 13:21 
User avatar
Isn't that lovely?

Joined: 30th Mar, 2008
Posts: 11168
Location: Devon
Mr Russell wrote:
Malc wrote:
Mr Russell wrote:
Is it because you don't cd to the fix directory in the second file?

Can you just add a manual cd in to where it is kicking you to root?

Disclaimer: I am not any good at this.


I could do, but I want to understand why I need to

Malc


As I say, my guess is because the second batch file starts from root and has no cd in it to say where to start from.


It just wouldn't work if it wasn't in the correct folder, it's in the fix folder for all the cmds (including the 3 start blahs at the end), but then changes back to the root folder after it finishes running. Also you'll note the 2nd batch file is called when it's in the fix folder, not before.

Malc

_________________
Where's the Kaboom? I was expecting an Earth shattering Kaboom!


Top
 Profile  
 
 Post subject: Re: Windos XP batch file query
PostPosted: Thu Nov 29, 2012 19:07 
User avatar
Sitting balls-back folder

Joined: 30th Mar, 2008
Posts: 10173
Either do the cd before setlocal, or endlocal then cd again. Based on the ridiculous batch-based build system I've just done at work, I suspect the current directory is part of the environment that's modified locally then popped off the stack at endlocal (or in this case, at batch exit). I see odd stuff too though, like setlocal variables being leaked if it exits early, so I'm not sure.


Top
 Profile  
 
 Post subject: Re: Windos XP batch file query
PostPosted: Fri Nov 30, 2012 10:08 
User avatar
Isn't that lovely?

Joined: 30th Mar, 2008
Posts: 11168
Location: Devon
Thanks, that does indeed fix it!

Woohoo!

Malc

_________________
Where's the Kaboom? I was expecting an Earth shattering Kaboom!


Top
 Profile  
 
 Post subject: Re: Windos XP batch file query
PostPosted: Wed Jan 16, 2013 15:27 
User avatar
Isn't that lovely?

Joined: 30th Mar, 2008
Posts: 11168
Location: Devon
Noticed another anomaly with this today:

Code:
FOR /F "tokens=1-18 delims=, " %%A IN ('ecplog -lt %clp1% -varval ^| find /i  "*START*"') DO (
      IF /i "%%E"=="(E)" (
            IF /i !count!==1 (
                  SET firstrecord=%%C
                  SET firstcardno=%%D
                  SET firstvalue=%%F
                  SET firstcash=%%G
                  SET firstdate=%%H
                  SET firsttime=%%J
                  SET firstconversion=%%K
                  SET firstbatch=%%M
                  SET firsttran=%%O
                  SET firstscheme=%%P
                  SET firstlognum=%%Q
                  SET firsttid=%%R
               )
      ) ELSE (
            IF /i !count!==1 (
                  SET firstrecord=%%C
                  SET firstcardno=%%D
                  SET firstvalue=%%E
                  SET firstcash=%%F
                  SET firstdate=%%G
                  SET firsttime=%%I
                  SET firstconversion=%%J
                  SET firstbatch=%%L
                  SET firsttran=%%N
                  SET firstscheme=%%O
                  SET firstlognum=%%P
                  SET firsttid=%%Q
               )
         )
      SET /A COUNT=!COUNT!+1



I have that as a For loop to read through a page of text, and depending on wether the 5th field is (E) or not it reads it in a slightly different way, now it's come to my attention that sometimes this field of text has a different structure from firstconversion onwards, however, if %E% is not set to (E) the batch file works fine.

Code:
*START* Record: 3, 123456******7890  20.01   0.00 11/11/2013 @ 12:34:56 Unconverted 9 5678 12345678 10/13
*START* Record: 3, 123456******7890 (E)  20.01   0.00 11/11/2013 @ 12:34:56 00/00/00, batch: 0, tran: 1234 9 567812345678 10/13


If the (E) isn't there then the whole line seems to be ignored and I get the details of the next line, but if it is there, then my transaction number (1234) gets set to the expiry date (10/13)!

Can any one see why?

Malc

_________________
Where's the Kaboom? I was expecting an Earth shattering Kaboom!


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Columbo, Kern, Satsuma and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.