Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FileDelete Delay ...


  • Please log in to reply
7 replies to this topic
cornell2
  • Members
  • 174 posts
  • Last active: Feb 04 2012 11:09 PM
  • Joined: 18 Mar 2005
I've come across a weird problem. Hoping for some insights.

I have (had) a fairly reliable script, that at one point uses RunWait to call "curl.exe" to request/download a file. This works no problem (and I am not looking for an alternative)
... for brevity:

RunWait, %comspec% /c "curl.exe "@C:\Inventoryfile.txt" https://secure.site.com/blahblah",,min
so, today, I decided I needed to add some simple code that would make sure there was no prior file

filedelete, C:\Inventoryfile.txt"
RunWait, %comspec% /c "curl.exe "@C:\Inventoryfile.txt" https://secure.site.com/blahblah",,min
ifnotexist, C:\Inventoryfile.txt
	msgbox, Something went wrong with the Inventory Download.

The problem is (or seems to be) that
1. filedelete does not appear to be 'complete' when RunWait starts.
the only way I can ensure that there is no file before RunWait, is to add a Sleep 500 between them.
2. if appears I have a similar issue after RunWait. RunWait ends after the file is downloaded - but still I get to that message box. If I add another sleep, then ifnotexist detects the file.
In other words ... this is the script that works

filedelete, C:\Inventoryfile.txt"
Sleep 500
RunWait, %comspec% /c "curl.exe "@C:\Inventoryfile.txt" https://secure.site.com/blahblah",,min
Sleep 500
ifnotexist, C:\Inventoryfile.txt
	msgbox, Something went wrong with the Inventory Download.

And it is still quirky. Any ideas or insight? What am I missing here?

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
you can loop a If FileExist() instead of sleep.

you are correct that FileDelete isn't an instant operation.

cornell2
  • Members
  • 174 posts
  • Last active: Feb 04 2012 11:09 PM
  • Joined: 18 Mar 2005
OK ... the approach is promising ... however - looping fileexist() alone won't do it. That will only solve the first half (before the RunWait download).

But afterwards. After the RunWait-download. There's my problem.

If the download was not successful, then the file does not exist. If it was successful, then the file does exist.

Often - AHK will come out of RunWait (whatever happened to the 'wait' part?) - my download will be successful, but RunWait completes and executes and then executes fileexist() before the download apparently finishes.
Looping won't solve the problem - becuase the file may indeed Not exist, or it may (that's why I am checking!)

Any thoughts?

Thanks!

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

But afterwards. After the RunWait-download. There's my problem.
If the download was not successful, then the file does not exist. If it was successful, then the file does exist.


Try checking the errorlevel.

RunWait, %comspec% /c "curl.exe "@C:\Inventoryfile.txt" https://secure.site.com/blahblah",,Min 
CurlErrorLevel := ErrorLevel

If ( CurlErrorLevel <> 0 )
   MsgBox, Something went wrong with the Inventory Download.

The listing of cURL error codes follows:

; http://downloads.openwrt.org/people/nico/man/man1/curl.1.html#lbAH

There exists a bunch of different error codes and their corresponding error messages that may appear during bad conditions. At the time of this writing, the exit codes are: 
1
Unsupported protocol. This build of curl has no support for this protocol. 
2
Failed to initialize. 
3
URL malformat. The syntax was not correct. 
4
URL user malformatted. The user-part of the URL syntax was not correct. 
5
Couldn't resolve proxy. The given proxy host could not be resolved. 
6
Couldn't resolve host. The given remote host was not resolved. 
7
Failed to connect to host. 
8
FTP weird server reply. The server sent data curl couldn't parse. 
9
FTP access denied. The server denied login. 
10
FTP user/password incorrect. Either one or both were not accepted by the server. 
11
FTP weird PASS reply. Curl couldn't parse the reply sent to the PASS request. 
12
FTP weird USER reply. Curl couldn't parse the reply sent to the USER request. 
13
FTP weird PASV reply, Curl couldn't parse the reply sent to the PASV request. 
14
FTP weird 227 format. Curl couldn't parse the 227-line the server sent. 
15
FTP can't get host. Couldn't resolve the host IP we got in the 227-line. 
16
FTP can't reconnect. Couldn't connect to the host we got in the 227-line. 
17
FTP couldn't set binary. Couldn't change transfer method to binary. 
18
Partial file. Only a part of the file was transferred. 
19
FTP couldn't download/access the given file, the RETR (or similar) command failed. 
20
FTP write error. The transfer was reported bad by the server. 
21
FTP quote error. A quote command returned error from the server. 
22
HTTP page not retrieved. The requested url was not found or returned another error with the HTTP error code being 400 or above. This return code only appears if -f/--fail is used. 
23
Write error. Curl couldn't write data to a local filesystem or similar. 
24
Malformed user. User name badly specified. 
25
FTP couldn't STOR file. The server denied the STOR operation, used for FTP uploading. 
26
Read error. Various reading problems. 
27
Out of memory. A memory allocation request failed. 
28
Operation timeout. The specified time-out period was reached according to the conditions. 
29
FTP couldn't set ASCII. The server returned an unknown reply. 
30
FTP PORT failed. The PORT command failed. Not all FTP servers support the PORT command, try doing a transfer using PASV instead! 
31
FTP couldn't use REST. The REST command failed. This command is used for resumed FTP transfers. 
32
FTP couldn't use SIZE. The SIZE command failed. The command is an extension to the original FTP spec RFC 959. 
33
HTTP range error. The range "command" didn't work. 
34
HTTP post error. Internal post-request generation error. 
35
SSL connect error. The SSL handshaking failed. 
36
FTP bad download resume. Couldn't continue an earlier aborted download. 
37
FILE couldn't read file. Failed to open the file. Permissions? 
38
LDAP cannot bind. LDAP bind operation failed. 
39
LDAP search failed. 
40
Library not found. The LDAP library was not found. 
41
Function not found. A required LDAP function was not found. 
42
Aborted by callback. An application told curl to abort the operation. 
43
Internal error. A function was called with a bad parameter. 
44
Internal error. A function was called in a bad order. 
45
Interface error. A specified outgoing interface could not be used. 
46
Bad password entered. An error was signaled when the password was entered. 
47
Too many redirects. When following redirects, curl hit the maximum amount. 
48
Unknown TELNET option specified. 
49
Malformed telnet option. 
51
The remote peer's SSL certificate wasn't ok 
52
The server didn't reply anything, which here is considered an error. 
53
SSL crypto engine not found 
54
Cannot set SSL crypto engine as default 
55
Failed sending network data 
56
Failure in receiving network data 
57
Share is in use (internal error) 
58
Problem with the local certificate 
59
Couldn't use specified SSL cipher 
60
Problem with the CA cert (path? permission?) 
61
Unrecognized transfer encoding 
62
Invalid LDAP URL 
63
Maximum file size exceeded 
XX
There will appear more error codes here in future releases. The existing ones are meant to never change

:)

cornell2
  • Members
  • 174 posts
  • Last active: Feb 04 2012 11:09 PM
  • Joined: 18 Mar 2005
Thanks for the help.
My problem is not with Curl! It is that AHK RunWait returns before the command is really finished. -- so the errorlevel checking is not accurate. (there is no error being returned becuase there IS no error) ... It's just that when AHK emerges from RunWait, the command it was processing is not finished. This is similar to the FileDelete problem.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
I am not able to reproduce it with :

RunWait, %comspec% /C "Dir C:\*.* /S > test.txt",, Min
Run Notepad.exe test.txt

Maybe this happens only with fast computers :roll:

Bartimus
  • Members
  • 237 posts
  • Last active: Nov 10 2016 05:01 PM
  • Joined: 10 Nov 2005
Just a shot in the dark, but what about not using RunWait and instead use Process, WaitClose?
filedelete, C:\Inventoryfile.txt" 

Run, %comspec% /c "curl.exe "@C:\Inventoryfile.txt" https://secure.site.com/blahblah",,min 

process, wait, curl.exe ; Make sure it's running first

process, waitclose, curl.exe ; wait's for curl.exe to close first instead of RunWait checking for comspec to close

ifnotexist, C:\Inventoryfile.txt 

   msgbox, Something went wrong with the Inventory Download.


cornell2
  • Members
  • 174 posts
  • Last active: Feb 04 2012 11:09 PM
  • Joined: 18 Mar 2005
Well, I'm not sure how I would use process in this case. As it stands, I had to recode everything with all sorts of checking-loops (checks .. if it fails, sleeps, checks again). Very kludgy and delicate. Extremely odd since this program has been working for almost 2 years! I must have deleted a character or did a weird replace and busted something ... that's all I can think of. I compared it to a recent older copy and there appears to be no difference in the core code. oh well, I am sure I'll find it one day. Thanks for the help!