Jump to content

Problem with RunWait


Recommended Posts

Hi everyone,

I have the following code:

#include <File.au3>; Include "File Management" User Defined Functions (UDF)
#Include <Array.au3>; Include "Array Management" User Defined Functions (UDF)

AutoItSetOption ( "TrayIconHide", 1 ); Hides AutoIt tray icon

; Start of Explicit Variables Listing
$FileList = _FileListToArray ( "C:\Downloads", "*.tif", 1 ); Variable used to hold the array of TIFF files found, the $iFlag=1 parameter restricts the search to files only (no folders)

;Start Step 1, Gather list of TIFF files
If @Error = 1 Then; If no TIFF files were found
    MsgBox ( 0, "Error" , "No TIFF Files Found." ); Display MsgBox with error message
    Exit; Exits
EndIf

For $i=0 to Ubound ( $FileList )-1; Returns the size of the array minus 1 (0 is reserved for the count of TIFF files)
RunWait ( @ComSpec & " /c " & "C:\Temp\MODI Images\exiftool.exe -a -u -g1"&$FileList&">"&$FileList&".txt", "", @SW_HIDE )
Next
; End Step 1, Gather list of TIFF files

_ArrayDisplay ( $FileList, "$FileList" ); Displays the array containing the found TIFF files

Basically, the problem is in the RunWait line. I am trying to pass all filenames in the FileList array to exiftool, using the a/u/g1 command line switches and piping the output for each TIFF file to a same named txt file. Can this even be done with AutoIt, or am I just wasting my time? The script seems to run, but all that is produced is a text file called ".txt" which contains the normal help output when you just run the command "exiftool.exe". There are two TIFF files in the folder, and exiftool is also in the folder.

Thanks,

CM

Link to comment
Share on other sites

do you need @ComSpec & " /c "??

EDIT: and look at this line:

For $i=0 to Ubound ( $FileList )-1; Returns the size of the array minus 1 (0 is reserved for the count of TIFF files)

shouldn't that be

For $i=1 to Ubound ( $FileList )-1; Returns the size of the array minus 1 (0 is reserved for the count of TIFF files)

with the reason in your comment?

Edited by Bert
Link to comment
Share on other sites

  • Developers

You are not using the Array values since you are missing the index value. something like this might work:

RunWait(@ComSpec & ' /c "C:\Temp\MODI Images\exiftool.exe" -a -u -g1 ' & $FileList[$i] & '>' & $FileList[$1] & ".txt", "", @SW_HIDE)

Jos :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

do you need @ComSpec & " /c "??

EDIT: and look at this line:

For $i=0 to Ubound ( $FileList )-1; Returns the size of the array minus 1 (0 is reserved for the count of TIFF files)

shouldn't that be

For $i=1 to Ubound ( $FileList )-1; Returns the size of the array minus 1 (0 is reserved for the count of TIFF files)

with the reason in your comment?

Hi,

lol - I have no idea (to either). The comspec bit I copied from an old script of mine that used the 7-Zip command line tool. It had command line switches and worked, so I thought if I copied the line from the old script, and just changed the .exe name, it would work. The other bit of code came from this post: http://www.autoitscript.com/forum/index.ph...mp;#entry529535 (a reply in my thread about half a dozen under this one, both threads are for the same script). It seemed to work when I typed it in - though as I said, I have no idea if it should be 0 to Ubound or 1 to Ubound. The comment at the end of the code is mine, to help in my understanding of AutoIt, I tend to place a comment after every single line of code. I was just guessing that the line returns the size of the array minus the index value zero, which I understood from the AutoIt helpfile was reserved for the total count of items in the array. Anyone clarify either/both of these?

Regards,

CM

Link to comment
Share on other sites

You are not using the Array values since you are missing the index value. something like this might work:

RunWait(@ComSpec & ' /c "C:\Temp\MODI Images\exiftool.exe" -a -u -g1 ' & $FileList[$i] & '>' & $FileList[$1] & ".txt", "", @SW_HIDE)

Jos :)

Ok, I just tried that, and this was the error I received:

Line 49 (File "C:\TempFiles\test\TIFFResolutionchanger.au3"):

RunWait ( @ComSpec & ' /c "C:\Temp\MODI Images\exiftool.exe" -a -u -g1 ' & $FileList[$i] & '>' & $FileList[$1] & ".txt", "", @SW_HIDE )

RunWait ( @ComSpec & ' /c "C:\Temp\MODI Images\exiftool.exe" -a -u -g1 ' & $FileList[$i] & '>' & $FileList[^ ERROR

Error: Variable used without being declared.

It doesn't seem to like the FileList[1]...

Regards,

CM

Link to comment
Share on other sites

Typo: change $1 to $i :)

Ok, cool. That gets rid of the error. It doesn't produce the correct output though. It might be something to do with the filenames of the TIFF's having spaces in them, but when I run this script on two TIFF files (Scan Test 3.tif and Scan Test 4.tif), two files are produced. One called Scan (with no extension), a 15 byte file with just the following in it: ======== Scan. The other file is just called 2.txt and it is a 0 byte file. Man, this is harder than what I thought it was going to be :)

CM

Link to comment
Share on other sites

Hi everyone,

Ok, I started from the beginning this morning, and this is what I have come up with so far:

#Include <File.au3>; Include "File Management" User Defined Functions (UDF)
#Include <Array.au3>; Include "Array Management" User Defined Functions (UDF)

AutoItSetOption ( "TrayIconHide", 1 ); Hides AutoIt tray icon

; Start of Explicit Variables Listing
Global $Count; Set variable for the "For" loop
Global $Path = "C:\Temp\MODI Images\"; Set variable for path to exiftool.exe, the exiftool.exe line does not use the last '\' so don't forget to include it in the variable.
; End of Explicit Variables Listing

;Insert pop up about function of program.
$Filename = InputBox ( "Step 1", "Please enter the filename of the file you wish to operate on. There is no need to include the .tif extension.", "", "", 300, 200 ); Request filename of TIFF file to operate on, and assign to variable.
;Insert file checking function here - if file entered does not exist, display error message and exit.
;Note that if you enter lowercase filename (scan.tif instead of Scan.tif), filename saved at end by exiftool will be in lowercase also. Need to fix.
$Pages = InputBox ( "Step 2", "Please enter the number of pages in the file you entered in the previous step.", "", "", 300, 200 ); Request number of pages in TIFF file, and assign to variable.
;Insert "Do you wish to have a log file produced (exiftool -a -u -g1 filename) of each file? Y/N" prompt and then add code to run necessary exiftool command if answer is Y.
;Insert Ready to process filename of $Pages, is this correct prompt.

For $Count = 0 to $Pages-1 Step 1; Runs a count, from IFD0 (first IFD number in a multi-page TIFF) to IFD$Pages. Note that because IFD starts from 0 and not 1, the "...to $Pages-1" is necessary. For example, a 15 page TIFF file will have entries for IFD0 to IFD14 inclusive, which is why we need the '-1'.
;RunWait ( @ComSpec & " /c " & "C:\Temp\MODI Images\exiftool.exe -P -IFD"&$Count&":XResolution=300 "&$Filename ); Original attempt at running exiftool command line. Couldn't get it to work.
;RunWait ( @ComSpec & " /c " & "C:\Temp\MODI Images\exiftool.exe -P -IFD"&$Count&":YResolution=300 "&$Filename ); Original attempt at running exiftool command line. Couldn't get it to work.
;ShellExecuteWait ( $Path&"exiftool.exe", "-P -IFD"&$Count&":XResolution=300 "&$Filename, "", "", @SW_HIDE ); Run the exiftool command. Original 'must include .tif extension in filename prompt' command.
;ShellExecuteWait ( $Path&"exiftool.exe", "-P -IFD"&$Count&":YResolution=300 "&$Filename, "", "", @SW_HIDE ); Run the exiftool command. Original 'must include .tif extension in filename prompt' command.
;Insert 'Please Wait - Processing' dialog in here
    $FileList = _FileListToArray ( $Path, "*.tif", 1 ); Insert TIFF files in folder into an array for processing.
    If @Error = 1 Then; Error 1 is "Path not found or invalid", Error 4 is "No File(s) Found".
        MsgBox ( 0, "Error", "Path"&$Path&" not found or is otherwise invalid." )
    ElseIf @Error = 4 Then
        MsgBox ( 0, "Error", "No TIFF files found in"&$Path&"." )
        Exit; Exits
    EndIf

    ShellExecuteWait ( $Path&"exiftool.exe", "-P -IFD"&$Count&":XResolution=300 "&$Filename&".tif", "", "", @SW_HIDE ); Run the exiftool command. Changed 'no need to include .tif extension in filename prompt' command.
    ShellExecuteWait ( $Path&"exiftool.exe", "-P -IFD"&$Count&":YResolution=300 "&$Filename&".tif", "", "", @SW_HIDE ); Run the exiftool command. Changed 'no need to include .tif extension in filename prompt' command.
Next

MsgBox ( 0, "Processing Complete", "Processing complete. TIFF file "&$Filename&".tif consisting of "&$Pages&" pages has now been set to 300DPI.", 5 ); Display MsgBox.
;Insert do you want to run script again prompt.

Exit; Exits

The bit beginning $FileList and ending with EndIf is my first attempt at integrating the 'auto filename listing' part of a few posts above. Basically, what I am trying to do is this:

1. I have a number of multi-page TIFF files that require changing to the EXIF headers. As multi-page TIFF's, the EXIF header I want to change (XResolution and YResolution) are listed in each IFD section inside the TIFF - so a 20 page TIFF will have IFD0 to IFD20 in the headers, each with XRes and YRes fields in it. That means the tool I use (exiftool) has to operate 40 times for this one file - 20 for XRes, 20 for YRes. Typing that in at a command prompt gets pretty tiring, especially when you have to do it to 60 files at a time. Thus, an AutoIt script to automate it.

2. Problem: I don't know in advance how many files there will be, nor do I know their filenames. Thus, the script needs to gather a list of all TIFF files in the folder and their names, to pass to the exiftool command line:

exiftool -IFD0:XResolution=300 filename1

exiftool -IFD1:XResolution=300 filename1

etc

3. Problem: I have no idea in advance how many pages each TIFF will have. exiftool (using exiftool -a -u -g1 filename1 >log.txt) will produce a text file with the EXIF headers, and I need the script to run this command on each file and then go right to the end of the file and see what the last IFD number is, so it can use from 0 to that number in the IFD part of the exiftool command. My current theory here is that I run:

exiftool -a -u -g1 filename1 >filename1.txt

and then the built-in to Windows:

find /c /i "IFD" filename1.txt >filename1c.txt

which should produce (in filename1c.txt)

---------- SCAN300.TXT: 3

I then need to use AutoIt somehow to just pick up the number. Not sure how to do that as yet.

4. Complicated as I say.

Now, what I have at the moment (all the above) is this: I put exiftool and all the TIFF's in the same folder and run the script. A box pops up asking me for the first filename. I enter it. It then asks me for the number of pages. I enter that manually (it will probably be the last thing I attempt to automate). The script then passes that info to exiftool, and the command runs. Afterwards, I run the script again, enter the second filename and go from there, running the script once for each file. You can see by the comments I've put in, what sort of features I want: eg a 'do you want to run this script again' prompt at the end (I have no idea how to do that, I've tried it before in other scripts and have failed each time - in a batch file I would use a goto command, but AutoIt doesn't have a goto command), a 'processing' dialog box while the exiftool command runs (it's a little slow when running on a 20 page TIFF file, so I need something there) etc. The processing dialog may be the most difficult after this 'array to send all the filenames to the command' bit (I am a newbie after all). I tried that this morning, and all I got was 40 blank GUI's (20 page TIFF, 20 boxes for XRes, 20 for YRes, 1 for each run of the exiftool command, so I had to delete that section).

Now that I've outlined what I am attempting to do, hopefully I can be better helped :) Any and all suggestions are greatly appreciated!

CM

Edited by romulous
Link to comment
Share on other sites

encase the file names in ""

This probably sounds stupid, but how do I do that? I tried this:

RunWait ( @ComSpec & "/c" $Path&"exiftool.exe -a -u -g1"&$FileList[$i]&">"&$FileList[$i]&".txt", "", @SW_HIDE )

Is that what you mean? Too many " cause the $FileList variable to be greyed out in SciTE, like a comment, which stops it working.

CM

Link to comment
Share on other sites

RunWait ( @ComSpec & " /c " & $Path &"exiftool.exe -a -u -g1" & $FileList[$i] &">" &$FileList[$i]&".txt", "", @SW_HIDE )

You have to be careful to also include any required spaces.

You may also have to use FileGetShortName($Path)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I prefer to use single quotes by default and then add double quotes to protect the paths with spaces.

RunWait('"' & @ComSpec & '" /c "' & $Path & '\exiftool.exe" -a -u -g1"' & $FileList[$i] & '">"' & $FileList[$i] & '.txt"', '', @SW_HIDE)

Edit:

Added missing backslash.

Edited by MHz
Link to comment
Share on other sites

@MHz

I agree. I often have to use that method as well. Sometimes FileGetShortName() works and sometimes it doesn't.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I prefer to use single quotes by default and then add double quotes to protect the paths with spaces.

RunWait('"' & @ComSpec & '" /c "' & $Path & '\exiftool.exe" -a -u -g1"' & $FileList[$i] & '">"' & $FileList[$i] & '.txt"', '', @SW_HIDE)

Edit:

Added missing backslash.

Ok, thanks. Now it runs without error. exiftool still doesn't produce any text files though, I am totally stumped. I cleaned up the code a bit this afternoon, and this is what I have now:

#Include <File.au3>; Include "File Management" User Defined Functions (UDF).
#Include <Array.au3>; Include "Array Management" User Defined Functions (UDF).

AutoItSetOption ( "TrayIconHide", 1 ); Hides AutoIt tray icon.

; Start of Explicit Variables Listing.
Global $Count; Set variable for the "For" loop in Step 2.
Global $exiftoolPath = "C:\Temp\MODI Images\"; Set variable for path to exiftool.exe.
; End of Explicit Variables Listing.

; Welcome Message.
MsgBox ( 0, "Welcome", "Welcome to the Automatic exiftool TIFF File Modifier. Please read the following and then click Ok to continue. When you click Ok, you will receive a number of pop-up messages requesting information." ); Welcome message

; Start Step 1, Obtain User Input.
$FilePath = InputBox ( "Path to Image Files", "Please enter the path to the image files you wish exiftool to operate on. The default path has been entered for you. Overwrite this if this is not correct. To confirm, click Ok or press Enter.", "C:\Temp\MODI Images\", "", 300, 200 ); Request user enter path to where TIFF files are located, default is C:\Temp\MODI Images.
$Filename = InputBox ( "Filename to Operate On", "Please enter the filename of the file you wish to operate on. There is no need to include the .tif extension. Then click Ok or press Enter.", "", "", 300, 200 ); Request filename of TIFF file to operate on, and assign to variable.

; Start of Code to Check Existence of $Filename
If FileExists ( $Filename ) Then
    MsgBox ( 4112, "Error", "The filename "&$Filename&" does not exist. Please input the filename again." ); Display error dialog if filename input by user does not exist - system modal dialog (4096) with stop sign icon (16).
    Exit; Exits.
EndIf
; End of Code to Check Existence of $Filename

$Pages = InputBox ( "Number of Pages in File", "Please enter the number of pages in the file "&$Filename&" and click Ok or press Enter.", "", "", 300, 200 ); Request number of pages in TIFF file, and assign to variable.
$Logfile = InputBox ( "Produce Logfile?", "Do you wish to have a logfile produced by exiftool, after it operates on "&$Filename&"? Y/N", "N", "", 300, 200 ); If Yes, then run the command exiftool -a -u -g1 on the TIFF file and pipe that to a text file.
If $Logfile = "Y" Then
    $MsgBox = MsgBox ( 1, "Processing", "Ready to operate on file "&$Filename&" with "&$Pages&" pages, producing a exiftool logfile. Is this correct? Click Ok or press Enter if correct, otherwise click Cancel to exit the program. You should then run the program again and enter the right information." ); Check information is correct dialog box.
ElseIf $Logfile = "N" Then
    $MsgBox = MsgBox ( 1, "Processing", "Ready to operate on file "&$Filename&" with "&$Pages&" pages, producing no exiftool logfile. Is this correct? Click Ok or press Enter if correct, otherwise click Cancel to exit the program. You should then run the program again and enter the right information." ); Check information is correct dialog box.
EndIf
; End of Step 1, Obtain User Input.

;Start Step 2, Gather List of TIFF Files.
$FileList = _FileListToArray ( $FilePath, "*.tif", 1 ); Variable used to hold the array of TIFF files found, the $iFlag=1 parameter restricts the search to files only (no folders)
If @Error = 1 Then; Error 1 is "Path not found or invalid".
    MsgBox ( 0, "Error", "Path "&$FilePath&" not found or is otherwise invalid." ); Display MsgBox with error message.
    Exit; Exits.
ElseIf @Error = 4 Then; Error 4 is "No File(s) Found".
    MsgBox ( 0, "Error", "No TIFF files found in "&$FilePath&"." )
    Exit; Exits.
EndIf
; End Step 2, Gather List of TIFF Files.

;EXPERIMENTAL START LOG
For $i = 1 To UBound ($FileList)-1
ShellExecuteWait ( $exiftoolPath&"exiftool.exe", "-a -u -g1"&$FileList[$i]&">"&$FileList[$i]&".txt", "", "", @SW_HIDE )
Next
;EXPERIMENTAL END LOG

; Start Step 5, Run exiftool Resolution Change Command
For $Count = 0 to $Pages-1 Step 1; Runs a count, from IFD0 (first IFD number in a multi-page TIFF) to IFD$Pages. Note that because IFD starts from 0 and not 1, the "...to $Pages-1" is necessary. For example, a 15 page TIFF file will have entries for IFD0 to IFD14 inclusive, which is why we need the '-1'.
    ShellExecuteWait ( $exiftoolPath&"exiftool.exe", "-P -IFD"&$Count&":XResolution=300 "&$Filename&".tif", "", "", @SW_HIDE ); Run the exiftool command to change the XResolution field. Initially tried a RunWait here, but couldn't get it to work, so changed it to ShellExecuteWait.
    ShellExecuteWait ( $exiftoolPath&"exiftool.exe", "-P -IFD"&$Count&":YResolution=300 "&$Filename&".tif", "", "", @SW_HIDE ); Run the exiftool command to change the YResolution field. Initially tried a RunWait here, but couldn't get it to work, so changed it to ShellExecuteWait.
Next
; End Step 5, Run exiftool Resolution Change Command

; Start Step 6, Display Exit Message.
MsgBox ( 0, "Processing Complete", "Processing complete. TIFF file "&$Filename&".tif consisting of "&$Pages&" pages has now been set to 300DPI." ); Display exit message.
; End Step 6, Display Exit Message.

Exit; Exits.

The problem bit is the bit in between the EXPERIMENTAL START and EXPERIMENTAL END tags. It's my attempt to replace RunWait with ShellExecuteWait, to see if I have any more luck getting the text files produced. I posted another thread (http://www.autoitscript.com/forum/index.php?showtopic=72760) for this particular part. I'm happy at how it has come along so far, but having to type in each filename manually is painful. I need to get this 'AutoIt looks in the folder, produces a listing of TIFF files there and then passes each one in turn to exiftool' bit working.

CM

Edited by romulous
Link to comment
Share on other sites

As I said earlier, beware of spaces. Try this

;
ShellExecuteWait ( $exiftoolPath&"exiftool.exe", "-a -u -g1 "&$FileList[$i]&">"&$FileList[$i]&".txt", "", "", @SW_HIDE )
;

EDIT: I also forsee where there might be a problem with path not being given for $FileList[$i] as in

For $I = 1 To Ubound($FileList)-1
   $FileList[$I] = "C:\Temp\MODI Images\" & $FileList[$I]

You can find out my using a MsgBox() inside that loop

If NOT FIleExists($FileList[$I] Then MsgBox(0, "TEST", "Ooooooops!")

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Why are there two active topics on the same issue...?

You said the other one was a separate issue, but the exact same code, and even the same point in the code is being discussed.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Why are there two active topics on the same issue...?

You said the other one was a separate issue, but the exact same code, and even the same point in the code is being discussed.

:)

And since I responded in this thread, I won't respond in the other. I have better things to do than post double responses.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...