Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

CMD file kicks out to prompt

Sep
6
0
Have been using 4DOS/TCC since days of downloading beta versions of 4DOS from Channel One BBS but has been awhile since I wrote more than a few lines of code for a CMD and am obviously a bit rusty.

I need help. Obviously Rex and his staff do not have the time to proofread and correct folks' BAT files but perhaps some other TCC aficionados might.

First the particulars:

TCC 12.11.76 Windows Vista [Version 6.0.6001]
TCC Build 76 Windows Vista Build 6001 Service Pack 1
3 windows open on desktop: TCC, Windows Explorer, iSpy.

Utilizing an older laptop with not enough disk space in system partition for service pack 2. I have serious doubts that using Service Pack 1 is the problem, but anything is possible. Please advise. I will change laptops but would prefer NOT to do so.

With a security camera, I am conducting an initial experiment with time-lapse photography as well as sharing with friends on a web site (http://www.webafterfive.com/garden/). I FTP a pic to the website and have an external hard drive storing the pic taken by iSpy (http://www.ispyconnect.com).

The CMD file below is the engine that runs this train. Essentially a pic (SNAP.JPG) is renamed according to time and date, uploaded to website, and saved to either 1 or 2 directories. Then the CMD file waits until another pic is created and the process repeats.

The problem is that the CMD kicks out to the command prompt sporadically. It has run for more than 2 weeks continuously, down to literally a matter of minutes. Then more than a week then less than a day and seemingly all points in between.

I cannot figure out why. Can you?

I welcome all comments, and I am sure there are more "elegant" ways to accomplish what I am doing. Feel free to point these out if you wish, but I am most interested in solving the problem of the CMD file kicking out to the prompt. It is probably something very simple that I just am unable to see. Thanks in advance.

-------------------------

setlocal
gosub NEWSCREEN

rem **SET PICTURE COUNTER
set x=0

rem **SET ARCHIVE DIRECTORIES
set homedir="I:\gardenpics\%@instr[0,8,%_datetime]"
set hourhomedir="I:\gardenpics\hourly\%@instr[0,8,%_datetime]"

rem **SET MIDNIGHT HOUR FOR NEW DAY DIRECTORY CREATION
set midnitehour=0

rem **SET FIRSTRUN MARKER
set firstrun=1

rem **SET NEW DAY MARKER
set newday=1

rem ** INITIAL SET HOUR COUNTERS AND ARCHIVE MARKERS
set t0hour=0
set t1hour=1
set t2hour=2
set t3hour=3
set t4hour=4
set t5hour=5
set t6hour=6
set t7hour=7
set t8hour=8
set t9hour=9
set t10hour=10
set t11hour=11
set t12hour=12
set t13hour=13
set t14hour=14
set t15hour=15
set t16hour=16
set t17hour=17
set t18hour=18
set t19hour=19
set t20hour=20
set t21hour=21
set t22hour=22
set t23hour=23

set a0hourarc=0
set a1hourarc=0
set a2hourarc=0
set a3hourarc=0
set a4hourarc=0
set a5hourarc=0
set a6hourarc=0
set a7hourarc=0
set a8hourarc=0
set a9hourarc=0
set a10hourarc=0
set a11hourarc=0
set a12hourarc=0
set a13hourarc=0
set a14hourarc=0
set a15hourarc=0
set a16hourarc=0
set a17hourarc=0
set a18hourarc=0
set a19hourarc=0
set a20hourarc=0
set a21hourarc=0
set a22hourarc=0
set a23hourarc=0

:BEGIN

rem **SET ERRORLEVELs
set newpic=1
set ftplogon=1
set cpypic=1

rem **LOOP UNTIL SNAP.JPG EXIST
if NOT exist "G:\Ispy\video\Garden\grabs\snap.jpg" goto :END

move /Q G:\Ispy\video\Garden\grabs\snap.jpg

rem **CHECK MOVE IF NOT SUCCESS START OVER
set newpic=%_?
if %newpic!=0 goto :END

rem **IFTP SESSION TO GODADDY.COM
iftp /P1 /Q "ftp://(actual name/password/location goes here)"

rem **CHECK IFTP IF NOT SUCCESS START OVER
set ftplogon=%_?
if %ftplogon!=0 goto :ENDIFTP

gosub :NEWSCREEN

copy /Q snap.jpg "ftp:"

rem **CHECK COPY IF NOT SUCCESS START OVER
set cpypic=%_?
if %cpypic!=0 goto :END
set /a x=x+1

gosub :NEWSCREEN

rem **THREE CYCLES TO GIVE TIME TO SEMI-SYNC WITH ISPY. COUNT TO SCREEN.
if %x gt 3 echo %x copies of SNAP.JPG sent to WAF.

rem **CHECK FOR MIDNIGHT HOUR or FIRST TIME RUN, NEW HOMEDIR AND NEW HOURHOMEDIR

iff %_hour==%midnitehour .or. %firstrun==1 then
set homedir="I:\gardenpics\%@instr[0,8,%_datetime]"
if not isdir %homedir md %homedir
set hourhomedir="I:\gardenpics\hourly\%@instr[0,8,%_datetime]"
if not isdir %hourhomedir md %hourhomedir
set firstrun=0
endiff

rem **RESET HOURLY ARCHIVE MARKERS AND NEW DAY
iff %_hour==%midnitehour .and. %newday==1 then
set a0hourarc=0
set a1hourarc=0
set a2hourarc=0
set a3hourarc=0
set a4hourarc=0
set a5hourarc=0
set a6hourarc=0
set a7hourarc=0
set a8hourarc=0
set a9hourarc=0
set a10hourarc=0
set a11hourarc=0
set a12hourarc=0
set a13hourarc=0
set a14hourarc=0
set a15hourarc=0
set a16hourarc=0
set a17hourarc=0
set a18hourarc=0
set a19hourarc=0
set a20hourarc=0
set a21hourarc=0
set a22hourarc=0
set a23hourarc=0
set newday=0
endiff

rem **ARCHIVE SNAP.JPG
:ARCHIVESNAP
set arcfile=garden%_datetime.jpg
copy /Q snap.jpg "%homedir\%arcfile"

rem **ARCHIVE HOURLY SNAP.JPG

iff %_hour==%t0HOUR .and. %a0HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a0HOURARC=1
elseiff %_hour==%t1HOUR .and. %a1HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a1HOURARC=1
elseiff %_hour==%t2HOUR .and. %a2HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a2HOURARC=1
elseiff %_hour==%t3HOUR .and. %a3HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a3HOURARC=1
elseiff %_hour==%t4HOUR .and. %a4HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a4HOURARC=1
elseiff %_hour==%t5HOUR .and. %a5HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a5HOURARC=1
elseiff %_hour==%t6HOUR .and. %a6HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a6HOURARC=1
elseiff %_hour==%t7HOUR .and. %a7HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a7HOURARC=1
elseiff %_hour==%t8HOUR .and. %a8HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a8HOURARC=1
elseiff %_hour==%t9HOUR .and. %a9HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a9HOURARC=1
elseiff %_hour==%t10HOUR .and. %a10HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a10HOURARC=1
elseiff %_hour==%t11HOUR .and. %a11HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a11HOURARC=1
elseiff %_hour==%t12HOUR .and. %a12HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a12HOURARC=1
elseiff %_hour==%t13HOUR .and. %a13HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a13HOURARC=1
elseiff %_hour==%t14HOUR .and. %a14HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a14HOURARC=1
elseiff %_hour==%t15HOUR .and. %a15HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a15HOURARC=1
elseiff %_hour===%t16HOUR .and. %a16HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a16HOURARC=1
elseiff %_hour==%t17HOUR .and. %a17HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a17HOURARC=1
elseiff %_hour==%t18HOUR .and. %a18HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a18HOURARC=1
elseiff %_hour==%t19HOUR .and. %a19HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a19HOURARC=1
elseiff %_hour==%t20HOUR .and. %a20HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a20HOURARC=1
elseiff %_hour==%t21HOUR .and. %a21HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a21HOURARC=1
elseiff %_hour==%t22HOUR .and. %a22HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
if %cpypic==0 set a22HOURARC=1
elseiff %_hour==%t23HOUR .and. %a23HOURARC==0 then
copy /Q snap.jpg "%hourhomedir\%arcfile"
set cpypic=%_?
iff %cpypic==0 then
set a23HOURARC=1
set newday=1
endiff
endiff

rem **REMOVE SNAP.JPG
del /K /Q snap.jpg

:ENDIFTP
iftp /c

rem **THREE CYCLES TO GIVE TIME TO SEMI-SYNC WITH ISPY
if %x gt 3 delay 12

:END
delay 1
goto :BEGIN

endlocal
quit


rem **SUBROUTINES
:NEWSCREEN
cls
echo.
echo.
return
 
Hmmm! I didn't read too carefully, but if the copy_to_ftp fails, you GOTO :END, skipping IFTP /C. It's possible (I don't know for sure) that using IFTP enough without a corresponding IFTP /C could lead to unexpected behavior.
 
And here are a few snippets (untested) showing how you might do with quite a lot fewer lines.
Code:
rem ** INITIAL SET HOUR COUNTERS AND ARCHIVE MARKERS
do i=0 to 23
    set t%[i]hour=%i
    set a%[i]hourarc=0
enddo
Code:
rem **RESET HOURLY ARCHIVE MARKERS AND NEW DAY
iff %_hour == %midnitehour .and. %newday == 1 then
    do i=0 to 23
        set a%[i]hourarc=0
    enddo
    set newday=0
endiff
Code:
rem **ARCHIVE HOURLY SNAP.JPG
do i=0 to 23
    iff %_hour == %t%[i]HOUR .and. %a%[i]HOURARC == 0 then
        copy /Q snap.jpg "%hourhomedir\%arcfile"
        set cpypic=%_?
        if %cpypic==0 set a%[i]HOURARC=1
        if %_hour == 23 set newday=1
        leave
    endiff
enddo
 
And here are a few snippets (untested) showing how you might do with quite a lot fewer lines.

This has an error.
Code:
rem **ARCHIVE HOURLY SNAP.JPG
do i=0 to 23
    iff %_hour == %t%[i]HOUR .and. %a%[i]HOURARC == 0 then
        copy /Q snap.jpg "%hourhomedir\%arcfile"
        set cpypic=%_?
        if %cpypic==0 set a%[i]HOURARC=1
        if %_hour == 23 set newday=1
        leave
    endiff
enddo

It should be should be:
Code:
...
iff %_hour == %[t%[i]HOUR] .and. %[a%[i]HOURARC] == 0 then
...
 
Hmmm! I didn't read too carefully, but if the copy_to_ftp fails, you GOTO :END, skipping IFTP /C. It's possible (I don't know for sure) that using IFTP enough without a corresponding IFTP /C could lead to unexpected behavior.
I agree with Vince. I would always close a connection before opening a new one.
And I can see only 1 "DELAY", what means that your batch runs the loops very fast. I have a similar job for copying files to a samba share (if there are new ones) and I let it run more relaxed with delays of at least a minute.
And I had also the problem that the job died if it ran for many days (but this was and still is 4nt v.8 if I remember right). To circumvent this problem I used the windows "task scheduler" to start a new job every hour. Perhaps you could do it in a similar way, depending on how often ispy produces new images (can you configure ispy to create files with date+time in the name?)
Tomorrow I will have to check the server if this stuff is still running :)
 
And since V.10 there is the FolderMonitor command. Actually this would be the silver bullet.
 
Code:
rem **ARCHIVE HOURLY SNAP.JPG
do i=0 to 23
    iff %_hour == %[t%[i]HOUR] .and. %[a%[i]HOURARC] == 0 then
        copy /Q snap.jpg "%hourhomedir\%arcfile"
        set cpypic=%_?
        if %cpypic==0 set a%[i]HOURARC=1
        if %_hour == 23 set newday=1
        leave
    endiff
enddo
And there's also the possibility, though small, that the loop above (or your IFF ... ELSEIFF version) will start before midnight and _HOUR will change before all the testing is done; in particular, before you get to "IF %_HOUR == 23" it may have changed to 0. It's not a bad idea to use another variable here, perhaps like this.
Code:
rem **ARCHIVE HOURLY SNAP.JPG
set testhour=%_hour
do i=0 to 23
    iff %testhour == %[t%[i]HOUR] .and. %[a%[i]HOURARC] == 0 then
        copy /Q snap.jpg "%hourhomedir\%arcfile"
        set cpypic=%_?
        if %cpypic==0 set a%[i]HOURARC=1
        if %testhour == 23 set newday=1
        leave
    endiff
enddo
 
And, with TCC v12, you could use an array to keep track of the archiving. It makes the script a little easier to read.
Code:
rem **CREATE ARCHIVE MARKER ARRAY; HOURARC[0] ... HOURARC[23]
setarray HOURARC[24]
 
rem ** INITIALIZE ARCHIVE MARKER ARRAY
do h=0 to 23
    set HOURARC[%h]=0
enddo
Code:
rem **RESET HOURLY ARCHIVE MARKERS AND NEW DAY
iff %_hour==%midnitehour .and. %newday==1 then
    do h=0 to 23
        set HOURARC[%h]=0
    enddo
    set newday=0
endiff
And there's a bug fix in the code below. Previously, I didn't have the newday test inside "iff %cpypic == 0".
Code:
rem **ARCHIVE HOURLY SNAP.JPG
set testhour=%_hour
do h=0 to 23
    iff %h == %testhour .and. %HOURARC[%h] == 0 then
        copy /Q snap.jpg "%hourhomedir\%arcfile"
        set cpypic=%_?
        iff %cpypic==0 then
            set HOURARC[%h]=1
            if %testhour == 23 set newday=1
        endiff
        leave
    endiff
enddo
 
Vince & Frank,
THANKS!
I have looked at this thing for TOO long. Both suggestions got my attention. I think Vince may have caught the mistake with the not ending the IFTP session. I left code as it was but entered an if %_iftp==1 iftp /c following the END marker. That may very well solve the problem. Only time will tell. Great suggestion! (and I just knew that someone would suggest a do loop. I admit it is more elegant and much more efficient.) As for the %testhour%, I haven't encountered a problem yet that I know of. As it is now the newday variable is set between 23:00:00 and 23:00:15 give or take. Roughly 279 pictures or loops later it turns midnight.

Ashamed to say I was not even aware of FolderMonitor but you are right in that it is indeed the silver bullet. At present, Ispy is taking a picture every 15 seconds and has (except for downtime) since May.Yes, iSpy can include date and time in file name but I much prefer TCC to do the renaming. I will definitely be working on an upgrade and include FolderMonitor in the works.

Thanks again to both you guys. I really appreciate you taking the time to help.

Ken
 
Well there is no question that the code suggested would improve the CMD but it did NOT fix the problem! Ran fine for a week and has kicked out twice in the last 36 hours! Any ideas?
 
Well there is no question that the code suggested would improve the CMD but it did NOT fix the problem! Ran fine for a week and has kicked out twice in the last 36 hours! Any ideas?
1. Please post the code you're using now.
2. Put this (below) at the beginning and wait for it to happen again.
Code:
on error (echo Error at line %_batchline & quit)
 
Hi Vince,
The code is the same as posted before with two changes, both the suggested ones.
1. Located under the END label:
:END
delay 1
if %_IFTP==1 iftp /c
goto :BEGIN
endlocal
quit
...
and,
2. The suggestion you just made at the beginning of file:
on error (echo Error at line %_batchline & quit)
setlocal
gosub :NEWSCREEN
...

I'll be happy to post the entire code again if necessary, but felt these short snippets would suffice for now. Agaiin, thanks for the assist.

Ken
 
I did not give attention to it yet, but TC creates dump files in the case of crashing.
Perhaps someone could help Ken further.
 
I did not give attention to it yet, but TC creates dump files in the case of crashing.
Perhaps someone could help Ken further.

Is it crashing? I'm not sure what "kicking out" entails. I've been assuming that the batch file ends unexpectedly, but the shell continues running. If that's what is happening, adding an ECHO ON to the start of the file should give clues about whether it always quits at the same place, and if so, where.
 
Another thing easy you can do is this. If necessary, add the column "Memory - working set" to Windows TASKMGR.EXE and monitor TCC's memory usage to see if it grows. Right now I'm running my version of your script (with DO loops and an array of hours and a strategically placed IFTP /C). Another instance of TCC is creating SNAP.JPG every 200 seconds. The memory usage I'm seeing is generally stable with an up-then-down change of 48K every few minutes. The FTP server's logs show every connection is being closed (that's good). But there's been an unexplained overall increase of about 200KB in an hour and a half. If that trend continues, it could get ugly in a week (but probably won't let this thing run that long).
 
Charles and Vince,
"Kicking oujt" meant that the CMD file stopped and kicked out to the TCC prompt. I am not ignoring you guys but am collecting data so to speak. Vince made another good suggestion wth echo Error at line %_batchline & quit. However that created its own problem in that the CMD file would "kick out" each time it found an error.
.
When I originally wrote the CMD file, I thought I wrote it in such a way that if it encountered an error it would loop around, begin the process again, and the CMD file would just keep on chuggin, but that is not the case. Something is causing the CMD file to stop and it is THAT that I wish to correct. I took Vince's suggestion and modified it. The beginning of my CMD file now looks like this...

on error (echo %_date %_time Error at line %_batchline >> g:\ftp_upload\errors.txt & start echo %_date %_time Error at line %_batchline)
setlocal
gosub :NEWSCREEN
...

I am now recording the errors in errors.txt as well as a new TCC window on the desktop. Hopefully when it kicks out now, I will have found the error.
I only modified the code last night from Vince's original suggestion.

BEFORE I modified it, I was keeping a record manually and line 86 was the biggest culprit (10 times) but I don't think that is the real problem because last night the same error occurred 10 time and the CMD file just kept on chuggin. I am taking the liberty of posting the code again, this time wth VIEW and line numbers. ERRORS.TXT thus far...

2012-08-10 01:32:45 Error at line 86
2012-08-10 01:57:26 Error at line 86
2012-08-10 02:40:09 Error at line 86
2012-08-10 02:55:05 Error at line 86
2012-08-10 03:28:18 Error at line 103
2012-08-10 04:14:35 Error at line 86
2012-08-10 04:28:00 Error at line 103
2012-08-10 04:48:05 Error at line 86
2012-08-10 04:50:49 Error at line 103
2012-08-10 05:41:54 Error at line 86
2012-08-10 05:49:06 Error at line 86
2012-08-10 06:08:10 Error at line 86
2012-08-10 06:08:56 Error at line 86

Once again, thanks for helping an old rook...
 
Perhaps the snap.jpg is actually generated and thus for can't be copied.
Configure ispy to create files with date+time in the name and just copy all new files except the latest.
But that's just a work-around...
 
1: on error (echo %_date %_time Error at line %_batchline >> g:\ftp_upload\errors.txt & start echo %_date %_time Error at line %_batchline)
2: setlocal
3: gosub :NEWSCREEN
4:
5: rem **SET PICTURE COUNTER
6: set x=0
7:
8: rem **SET ARCHIVE DIRECTORIES
9: set homedir="I:\gardenpics\%@instr[0,8,%_datetime]"
10: set hourhomedir="I:\gardenpics\hourly\%@instr[0,8,%_datetime]"
11:
12:
13: rem **SET MIDNIGHT HOUR FOR NEW DAY DIRECTORY CREATION
14: rem **AND RESET HOUR COUNTERS AND ARCHIVE MARKERS
15: set midnitehour=0
16:
17:
18: rem **SET FIRSTRUN MARKER
19: set firstrun=1
20:
21: rem **SET NEW DAY MARKER
22: set newday=1
23:
24: rem ** INITIAL SET HOUR COUNTERS AND ARCHIVE MARKERS
25: set t0hour=0
26: set t1hour=1
27: set t2hour=2
28: set t3hour=3
29: set t4hour=4
30: set t5hour=5
31: set t6hour=6
32: set t7hour=7
33: set t8hour=8
34: set t9hour=9
35: set t10hour=10
36: set t11hour=11
37: set t12hour=12
38: set t13hour=13
39: set t14hour=14
40: set t15hour=15
41: set t16hour=16
42: set t17hour=17
43: set t18hour=18
44: set t19hour=19
45: set t20hour=20
46: set t21hour=21
47: set t22hour=22
48: set t23hour=23
49:
50:
51: set a0hourarc=0
52: set a1hourarc=0
53: set a2hourarc=0
54: set a3hourarc=0
55: set a4hourarc=0
56: set a5hourarc=0
57: set a6hourarc=0
58: set a7hourarc=0
59: set a8hourarc=0
60: set a9hourarc=0
61: set a10hourarc=0
62: set a11hourarc=0
63: set a12hourarc=0
64: set a13hourarc=0
65: set a14hourarc=0
66: set a15hourarc=0
67: set a16hourarc=0
68: set a17hourarc=0
69: set a18hourarc=0
70: set a19hourarc=0
71: set a20hourarc=0
72: set a21hourarc=0
73: set a22hourarc=0
74: set a23hourarc=0
75:
76: :BEGIN
77:
78: rem **SET ERRORLEVELs
79: set newpic=1
80: set ftplogon=1
81: set cpypic=1
82:
83: rem **LOOP UNTIL SNAP.JPG EXIST
84: if NOT exist "G:\Ispy\video\Garden\grabs\snap.jpg" goto :END
85:
86: move /Q G:\Ispy\video\Garden\grabs\snap.jpg
87:
88: rem **CHECK MOVE IF NOT SUCCESS START OVER
89: set newpic=%_?
90: if %newpic!=0 goto :END
91:
92: rem **IFTP SESSION TO GODADDY.COM
93: rem iftp /P1 /Q
94: iftp /P1 /Q "ftp://(actual name/password/location goes here)"
95:
96: rem **CHECK IFTP IF NOT SUCCESS START OVER
97: set ftplogon=%_?
98: if %ftplogon!=0 goto :ENDIFTP
99:
100:
101: gosub :NEWSCREEN
102:
103: copy /Q snap.jpg "ftp:"
104:
105: rem **CHECK COPY IF NOT SUCCESS START OVER
106: set cpypic=%_?
107: if %cpypic!=0 goto :END
108: set /a x=x+1
109:
110: gosub :NEWSCREEN
111:
112: rem **THREE CYCLES TO GIVE TIME TO SEMI-SYNC WITH ISPY
113: if %x gt 3 echo %x copies of SNAP.JPG sent to WAF.
114:
115:
116:
117: rem **CHECK FOR MIDNIGHT HOUR or FIRST TIME RUN, NEW HOMEDIR AND NEW HOURHOMEDIR
118:
119: iff %_hour==%midnitehour .or. %firstrun==1 then
120: set homedir="I:\gardenpics\%@instr[0,8,%_datetime]"
121: if not isdir %homedir md %homedir
122: set hourhomedir="I:\gardenpics\hourly\%@instr[0,8,%_datetime]"
123: if not isdir %hourhomedir md %hourhomedir
124: set firstrun=0
125: endiff
126:
127: rem **RESET HOURLY ARCHIVE MARKERS AND NEW DAY
128: iff %_hour==%midnitehour .and. %newday==1 then
129: set a0hourarc=0
130: set a1hourarc=0
131: set a2hourarc=0
132: set a3hourarc=0
133: set a4hourarc=0
134: set a5hourarc=0
135: set a6hourarc=0
136: set a7hourarc=0
137: set a8hourarc=0
138: set a9hourarc=0
139: set a10hourarc=0
140: set a11hourarc=0
141: set a12hourarc=0
142: set a13hourarc=0
143: set a14hourarc=0
144: set a15hourarc=0
145: set a16hourarc=0
146: set a17hourarc=0
147: set a18hourarc=0
148: set a19hourarc=0
149: set a20hourarc=0
150: set a21hourarc=0
151: set a22hourarc=0
152: set a23hourarc=0
153: set newday=0
154: endiff
155:
156:
157: rem **ARCHIVE SNAP.JPG
158: :ARCHIVESNAP
159: set arcfile=garden%_datetime.jpg
160: copy /Q snap.jpg "%homedir\%arcfile"
161:
162: rem **ARCHIVE HOURLY SNAP.JPG
163:
164:
165: iff %_hour==%t0HOUR .and. %a0HOURARC==0 then
166: copy /Q snap.jpg "%hourhomedir\%arcfile"
167: set cpypic=%_?
168: if %cpypic==0 set a0HOURARC=1
169: elseiff %_hour==%t1HOUR .and. %a1HOURARC==0 then
170: copy /Q snap.jpg "%hourhomedir\%arcfile"
171: set cpypic=%_?
172: if %cpypic==0 set a1HOURARC=1
173: elseiff %_hour==%t2HOUR .and. %a2HOURARC==0 then
174: copy /Q snap.jpg "%hourhomedir\%arcfile"
175: set cpypic=%_?
176: if %cpypic==0 set a2HOURARC=1
177: elseiff %_hour==%t3HOUR .and. %a3HOURARC==0 then
178: copy /Q snap.jpg "%hourhomedir\%arcfile"
179: set cpypic=%_?
180: if %cpypic==0 set a3HOURARC=1
181: elseiff %_hour==%t4HOUR .and. %a4HOURARC==0 then
182: copy /Q snap.jpg "%hourhomedir\%arcfile"
183: set cpypic=%_?
184: if %cpypic==0 set a4HOURARC=1
185: elseiff %_hour==%t5HOUR .and. %a5HOURARC==0 then
186: copy /Q snap.jpg "%hourhomedir\%arcfile"
187: set cpypic=%_?
188: if %cpypic==0 set a5HOURARC=1
189: elseiff %_hour==%t6HOUR .and. %a6HOURARC==0 then
190: copy /Q snap.jpg "%hourhomedir\%arcfile"
191: set cpypic=%_?
192: if %cpypic==0 set a6HOURARC=1
193: elseiff %_hour==%t7HOUR .and. %a7HOURARC==0 then
194: copy /Q snap.jpg "%hourhomedir\%arcfile"
195: set cpypic=%_?
196: if %cpypic==0 set a7HOURARC=1
197: elseiff %_hour==%t8HOUR .and. %a8HOURARC==0 then
198: copy /Q snap.jpg "%hourhomedir\%arcfile"
199: set cpypic=%_?
200: if %cpypic==0 set a8HOURARC=1
201: elseiff %_hour==%t9HOUR .and. %a9HOURARC==0 then
202: copy /Q snap.jpg "%hourhomedir\%arcfile"
203: set cpypic=%_?
204: if %cpypic==0 set a9HOURARC=1
205: elseiff %_hour==%t10HOUR .and. %a10HOURARC==0 then
206: copy /Q snap.jpg "%hourhomedir\%arcfile"
207: set cpypic=%_?
208: if %cpypic==0 set a10HOURARC=1
209: elseiff %_hour==%t11HOUR .and. %a11HOURARC==0 then
210: copy /Q snap.jpg "%hourhomedir\%arcfile"
211: set cpypic=%_?
212: if %cpypic==0 set a11HOURARC=1
213: elseiff %_hour==%t12HOUR .and. %a12HOURARC==0 then
214: copy /Q snap.jpg "%hourhomedir\%arcfile"
215: set cpypic=%_?
216: if %cpypic==0 set a12HOURARC=1
217: elseiff %_hour==%t13HOUR .and. %a13HOURARC==0 then
218: copy /Q snap.jpg "%hourhomedir\%arcfile"
219: set cpypic=%_?
220: if %cpypic==0 set a13HOURARC=1
221: elseiff %_hour==%t14HOUR .and. %a14HOURARC==0 then
222: copy /Q snap.jpg "%hourhomedir\%arcfile"
223: set cpypic=%_?
224: if %cpypic==0 set a14HOURARC=1
225: elseiff %_hour==%t15HOUR .and. %a15HOURARC==0 then
226: copy /Q snap.jpg "%hourhomedir\%arcfile"
227: set cpypic=%_?
228: if %cpypic==0 set a15HOURARC=1
229: elseiff %_hour===%t16HOUR .and. %a16HOURARC==0 then
230: copy /Q snap.jpg "%hourhomedir\%arcfile"
231: set cpypic=%_?
232: if %cpypic==0 set a16HOURARC=1
233: elseiff %_hour==%t17HOUR .and. %a17HOURARC==0 then
234: copy /Q snap.jpg "%hourhomedir\%arcfile"
235: set cpypic=%_?
236: if %cpypic==0 set a17HOURARC=1
237: elseiff %_hour==%t18HOUR .and. %a18HOURARC==0 then
238: copy /Q snap.jpg "%hourhomedir\%arcfile"
239: set cpypic=%_?
240: if %cpypic==0 set a18HOURARC=1
241: elseiff %_hour==%t19HOUR .and. %a19HOURARC==0 then
242: copy /Q snap.jpg "%hourhomedir\%arcfile"
243: set cpypic=%_?
244: if %cpypic==0 set a19HOURARC=1
245: elseiff %_hour==%t20HOUR .and. %a20HOURARC==0 then
246: copy /Q snap.jpg "%hourhomedir\%arcfile"
247: set cpypic=%_?
248: if %cpypic==0 set a20HOURARC=1
249: elseiff %_hour==%t21HOUR .and. %a21HOURARC==0 then
250: copy /Q snap.jpg "%hourhomedir\%arcfile"
251: set cpypic=%_?
252: if %cpypic==0 set a21HOURARC=1
253: elseiff %_hour==%t22HOUR .and. %a22HOURARC==0 then
254: copy /Q snap.jpg "%hourhomedir\%arcfile"
255: set cpypic=%_?
256: if %cpypic==0 set a22HOURARC=1
257: elseiff %_hour==%t23HOUR .and. %a23HOURARC==0 then
258: copy /Q snap.jpg "%hourhomedir\%arcfile"
259: set cpypic=%_?
260: iff %cpypic==0 then
261: set a23HOURARC=1
262: set newday=1
263: endiff
264: endiff
265:
266: rem **REMOVE SNAP.JPG
267: del /K /Q snap.jpg
268:
269: :ENDIFTP
270: iftp /c
271:
272: rem **THREE CYCLES TO GIVE TIME TO SEMI-SYNC WITH ISPY
273: if %x gt 3 delay 12
274:
275: :END
276: delay 1
277: if %_IFTP==1 iftp /c
278: goto :BEGIN
279:
280: endlocal
281: quit
282:
283:
284:
285:
286: rem **SUBROUTINES
287: :NEWSCREEN
288: cls
289: echo.
290: echo.
291: return
 
Frank stated that iSpy is creating the file asynchronously to your batch script checking its existence. If the file has been opened by iSpy but not completely written or closed before you check if it exists, you will try to move it and that won't succeed.

One possible solution is if the file exists, delay for a couple seconds before accessing it. However, that can lead to issues on the other side of the timing window. You mentioned that iSpy is producing images every 15 seconds. If you happen to access the file just as (or before) iSpy is creating a new one, that could lead to its own set of issues.

Perhaps using FOLDERMONITOR and letting iSpy use timestamps in its names is what you need.
foldermonitor G:\Ispy\video\Garden\grabs created forever CopySnap.btm "%%_folderfile1"

Where CopySnap.btm handles the MOVE, and copy to FTP, and renaming operations but doesn't loop.

-Scott
 

Similar threads

Replies
0
Views
1K
Back
Top