HeffeD Posted September 10, 2007 Share Posted September 10, 2007 Hi there, I'm very new to AutoIt and I'm having trouble converting a very simple .bat file to AutoIt. I'm sure it's a simple problem, but I can't figure it out for the life of me and I'm getting frustrated. All the .bat file does is update some source code from Sourceforge's SVN servers using TortoiseSVN. This is the contents of the .bat. CD C:\Program Files\TortoiseSVN\bin TortoiseProc.exe /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0 The .bat file functions as it should. The help file shows the format for DOS commands as: RunWait(@ComSpec & " /c " & "commandName") I've tried, RunWait(@ComSpec & " /c " & "TortoiseProc.exe /command:update /path:""C:\Downloads\KoLmafiaSVN"" /notempfile /closeonend:0") Which closest matches the example, with the command line arguments going into the "commandName" placeholder. I'm suspecting though that I'm passing it an incomplete path because I haven't told it where to find TortoiseProc.exe. So I figured that I needed to tell AutoIt to do the equivalent of "CD" in a .bat file and tell it the directory. (C:\Program Files\TortoiseSVN\bin) So I tried, RunWait(@ComSpec & " /c:\Program Files\TortoiseSVN\bin " & "TortoiseProc.exe /command:update /path:""C:\Downloads\KoLmafiaSVN"" /notempfile /closeonend:0") And even RunWait(@ComSpec & " /c " & "Program Files\TortoiseSVN\bin\TortoiseProc.exe /command:update /path:""C:\Downloads\KoLmafiaSVN"" /notempfile /closeonend:0") I've tried other things as well, but these three seemed the most likely to work from what I could gather from the help file. All that happens with any of these three options is that a command window opens and closes instantly with nothing actually happening in the com window. I've also tried ShellExecuteWait in case I was invoking the com window improperly, which nets me an error message that the file could not be found and to make sure I spelled it correctly. I'm sure it's spelled correctly, I'm just messing up the syntax somewhere. So what am I doing wrong? It looks like I should have covered the proper syntax according to the help file with one of the options shown above. Any help would be appreciated! Link to comment Share on other sites More sharing options...
MadBoy Posted September 10, 2007 Share Posted September 10, 2007 (edited) RunWait(@ComSpec & " /c " & '"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0') I think that should do it. Due to " that has to be in the command line you need to use ' as quotes. Edited September 10, 2007 by MadBoy My little company: Evotec (PL version: Evotec) Link to comment Share on other sites More sharing options...
Developers Jos Posted September 10, 2007 Developers Share Posted September 10, 2007 or try: RunWait(@ComSpec & ' /c ""Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0"') 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 More sharing options...
Developers Jos Posted September 10, 2007 Developers Share Posted September 10, 2007 (edited) RunWait(@ComSpec & " /c " & '"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0') I think that should do it. Due to " that has to be in the command line you need to use ' as quotes.I prefer single-quotes too but double-quotes only will work too. Just double them inside the string.. Jos Edited September 10, 2007 by JdeB 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 More sharing options...
ssubirias3 Posted September 10, 2007 Share Posted September 10, 2007 This could be wrong, but have you tried just using Run() or RunWait() without @ComSpec $command = 'TortoiseProc.exe /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0' $wkdir = 'C:\Program Files\TortoiseSVN\bin' Run($command, $wkdir) Link to comment Share on other sites More sharing options...
Developers Jos Posted September 10, 2007 Developers Share Posted September 10, 2007 This could be wrong, but have you tried just using Run() or RunWait() without @ComSpec $command = 'TortoiseProc.exe /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0' $wkdir = 'C:\Program Files\TortoiseSVN\bin' Run($command, $wkdir) Should work fine to BUT you need to specify the full path in the first parameter when that directory isn't defined in teh seatch path! 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 More sharing options...
MHz Posted September 10, 2007 Share Posted September 10, 2007 FileChangeDir() does similar as CD in a CMD file. So the closest would be: If FileChangeDir(@ProgramFilesDir & '\TortoiseSVN\bin') Then Run('TortoiseProc.exe /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0') EndIfoÝ÷ Ù8Z¶Ç±¬(®H§Ø«~í«ew¨«vëü¨ºë ¬¥ç-éìzÛayj+)à*ì¢Ø^{ºÖëâ{W¬{ayj+)à*ÚºÚ"µÍ[ØZ] ÛÛTÜXÈ [È ][ÝÈØÈÜÚÙTØË^HØÛÛ[X[]HÜ]][ÝÉ][ÝÐÎÌLÑÝÛØYÉÌLÒÛÓXYXTÕ][ÝÉ][ÝÈÛÝ[[HØÛÜÙ[Û[ ][ÝËÙÜ[Q[Ñ [È ÌÎNÉÌLÕÜÚÙTÕÌLØ[ÌÎNÊ The Working dir is only valid within the instance of @Comspec. Link to comment Share on other sites More sharing options...
HeffeD Posted September 10, 2007 Author Share Posted September 10, 2007 Wow, you guys are fast! A million thanks for everybodies help! @MadBoy, The help file specified that if you were using quotes inside quotes, either "" or ' is correct. I think the ' looks cleaner, but I tried that with the same results as "" and it didn't work either, so I stuck with "". @JdeB, No, that didn't work. Same results as my previous attempts. Opening a com window then having it immediately close. @ssubirias3, That helps me think about formatting things differently, thanks! It doesn't work though. I get an error that it can't open the external application. Maybe I'll try that with ShellExecuteWait. @MHz, Aha! Both of those work! I don't know why it didn't occur to me to look in the "file" section... It seems obvious now. I searched for both "change" and "directory", but couldn't find what I was looking for. If I search for "dir" I can find it. I guess part of the learning curve is also how to search the help file properly. You guys are great! Link to comment Share on other sites More sharing options...
ssubirias3 Posted September 10, 2007 Share Posted September 10, 2007 @ssubirias3, That helps me think about formatting things differently, thanks! It doesn't work though. I get an error that it can't open the external application. Maybe I'll try that with ShellExecuteWait.To JdeB's point I didn't realize your program wasn't in your path. See if this works $app = 'C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe' $command = ' /command:update /path:"C:\Downloads\KoLmafiaSVN" /notempfile /closeonend:0' $wkdir = 'C:\Program Files\TortoiseSVN\bin' Run($app & $command, $wkdir) Sorry about the minor oversight, and thanks JdeB for keeping me honest . Link to comment Share on other sites More sharing options...
HeffeD Posted September 10, 2007 Author Share Posted September 10, 2007 To JdeB's point I didn't realize your program wasn't in your path. See if this worksYes, that does work! Thanks for the great example. I used the concept in my script. This is the script that I came up with. It does what I want it to do, but I was hoping you experts could critique it and tell me if there is a more efficient way to do things than the way I'm doing them. What it does: -Updates the source code from SVN. (Using TortoiseSVN) -Compiles a new .jar file. (Using Apache Ant, but it doesn't need to be called directly) -Creates a backup of the existing .jar by giving it a timestamp and changing the .jar extension to .bak and moving the old file to a new directory. -Checks to make sure the backup was successful, then copies the new build from the source directory to my working directory. I'm not exactly happy with the final If, Then, Else... statement. All I want it to do is verify the file and tell me if it didn't copy. I don't really need a 'Then'. Anyway, does anyone have any tips on this script? Thanks in advance for taking your time to look at my sloppy script! ;Update from SVN. RunWait(@ComSpec & " /c TortoiseProc.exe /command:update /path:""C:\Downloads\KoLmafiaSVN"" /notempfile /closeonend:1", @ProgramFilesDir & '\TortoiseSVN\bin') ;Build new .jar file. RunWait(@ComSpec & " /c " & "ant", "C:\Downloads\KoLmafiaSVN") ;Rename backup file with timestamp. $OrigFile = "C:\Downloads\KoLmafia\KoLmafia.jar" $NewDest = "C:\Downloads\KoLmafia\OldJar\" $NewExt = StringReplace("KoLmafia.jar", ".jar", ".bak") $t = FileGetTime($OrigFile, 0, 0) $TStamp = $t[1] & "-" & $t[2] & "t" & $t[3] & "." & $t[4] $NewFile = $NewDest & $TStamp & $NewExt ;Move backup file to backup directory. FileMove($OrigFile, $NewFile) ;Check to ensure file was moved to proper directory. If FileExists($NewFile) Then FileCopy("C:\Downloads\KoLmafiaSVN\dist\KoLmafia.jar", "C:\Downloads\KoLmafia\", 1) Else MsgBox(4096, "Failure!", "Backup Wasn't Made!") EndIf ;Check to ensure file copy was successful. If FileExists("C:\Downloads\KoLmafia\KoLmafia.jar") Then Sleep(1);Basically a dummy command because I don't know how to make a dead Then... Any thoughts? Else MsgBox(4096, "Failure!", "File wasn't copied!") EndIf My next step is to make the script delete the backup files older than a specified date. Thanks again for any suggestions you may have on my script. Link to comment Share on other sites More sharing options...
MHz Posted September 10, 2007 Share Posted September 10, 2007 I'm not exactly happy with the final If, Then, Else... statement. All I want it to do is verify the file and tell me if it didn't copy. I don't really need a 'Then'.To skip the use of Else by using Not ;Check to ensure file copy was successful. If Not FileExists("C:\Downloads\KoLmafia\KoLmafia.jar") Then MsgBox(4096, "Failure!", "File wasn't copied!") EndIfoÝ÷ ØêãºË^ØÂ+ajëh×6;Check to ensure file was moved to proper directory. If FileExists($NewFile) Then If Not FileCopy("C:\Downloads\KoLmafiaSVN\dist\KoLmafia.jar", "C:\Downloads\KoLmafia\", 1) Then MsgBox(4096, "Failure!", "File wasn't copied!") EndIf Else MsgBox(4096, "Failure!", "Backup Wasn't Made!") EndIf Link to comment Share on other sites More sharing options...
HeffeD Posted September 11, 2007 Author Share Posted September 11, 2007 Thanks for your help MHz, I really like your final example. It's nice and tidy. I'm all for accomplishing the same result with less lines of code! Link to comment Share on other sites More sharing options...
ssubirias3 Posted September 11, 2007 Share Posted September 11, 2007 Thanks for your help MHz, I really like your final example. It's nice and tidy. I'm all for accomplishing the same result with less lines of code!I like less lines too! Here's my stab at cleaning up the code. Note JdeB and MHz are light years ahead of me and I'd take anything they gave you over what I would come up with. There's so many ways to skin this cat. It's now 18 lines instead of your original 25. Let's hope it still works for you ; Variables Local $pSVN = "C:\Downloads\KoLmafia" Local $OrigFile = $pSVN & "\KoLmafia.jar" Local $NewDest = $pSVN & "\OldJar\" ;Update from SVN. RunWait(@ComSpec & " /c TortoiseProc.exe /command:update /path:" & $pSVN & "SVN /notempfile /closeonend:1", @ProgramFilesDir & '\TortoiseSVN\bin') ;Build new .jar file. RunWait(@ComSpec & " /c ant", $pSVN & "SVN") ;Rename backup file with timestamp. $t = FileGetTime($OrigFile, 0, 0) $TStamp = $t[1] & "-" & $t[2] & "t" & $t[3] & "." & $t[4] ;Move backup file to backup directory. $NewFile = FileMove($OrigFile, $NewDest & $TStamp & "KoLmafia.bak") ;Check to ensure file was moved to proper directory. If $NewFile == 1 Then FileCopy($pSVN & "SVN\dist\KoLmafia.jar", $pSVN & "\", 1) If $NewFile == 0 Then MsgBox(4096, "Failure!", "Backup Wasn't Made!") ;Check to ensure file copy was successful. If Not FileExists($pSVN & "\KoLmafia.jar") Then MsgBox(4096, "Failure!", "File wasn't copied!")oÝ÷ Ù.q©ÚÊ,µ§$Ê«½ªâi¹^²X¤zØb²'ò¢ì׶Zèv'¶z)Þ³*.ÈhÇ·Ý«¢+ØìYÉ¥±Ì)1½°ÀÌØíÁMY8ôÅÕ½ÐíèÀäÈí½Ý¹±½ÌÀäÈí-½1µ¥ÅÕ½Ðì°ÀÌØí=É¥¥±ôÀÌØíÁMY8µÀìÅÕ½ÐìÀäÈí-½1µ¥¹©ÈÅÕ½Ðì°ÀÌØí9ÝÍÐôÀÌØíÁMY8µÀìÅÕ½ÐìÀäÈí=±)ÈÀäÈìÅÕ½Ðì Link to comment Share on other sites More sharing options...
HeffeD Posted September 11, 2007 Author Share Posted September 11, 2007 Hey, thanks for the tips ssubirias3! Lot's of useful information there. I'm really pleased how helpful you advanced users are to new users such as myself. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now