Cyborg5000 Posted May 7, 2018 Share Posted May 7, 2018 (edited) Iam trying to loop a batch to create other batch... that means from batch 1 (listed with commands) iam trying to read 1st line and create another batch 2. However once the batch 2 is executed, batch 2 will get deleted, also from batch1 first line entry will get removed... but not working:--- expandcollapse popupFileClose($mainfile) ; =============================== End of Read given data and Create Transfer Batch Call ("_checkfile") EndFunc ;==>Submit Func _checkfile() $file=FileOpen("C:\Windows\pyth\transf.bat",0) While 1 $result=FileReadLine($file) Call ("_bat") If @error = -1 Then ExitLoop; end of file FileClose($file); do something with $result ... WEnd EndFunc Func _bat() Global $newbatch = ("C:\Windows\pyth\bat\trans.bat") $readfile = FileOpen("C:\Windows\pyth\transf.bat",0) $line2 = FileReadLine($readfile,1) FileOpen($newbatch, 0) FileWrite($newbatch, $line2 & @CRLF) While 1 $readfile1 = FileOpen("C:\Windows\pyth\transf.bat",0) $result1=FileReadLine($readfile1) _FileWriteToLine($result1, 1, "", True) ShellExecuteWait("trans.bat", "", "C:\Windows\pyth\bat\", "") FileDelete ($newbatch) If @error = -1 Then ExitLoop; end of file FileClose($readfile) FileClose($newbatch) WEnd EndFunc Edited May 7, 2018 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
wisem2540 Posted May 7, 2018 Share Posted May 7, 2018 Is there a reason you need BAT files? You could probably do all the commands in autoit directly. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 7, 2018 Share Posted May 7, 2018 This section is written wrong. ; This While 1 $result = FileReadLine($file) _bat() If @error = -1 Then ExitLoop ; end of file FileClose($file) ; do something with $result ... WEnd ; should be written like this While 1 $result = FileReadLine($file) If @error = -1 Then ExitLoop ; this was in the wrong place _bat() FileClose($file) ; do something with $result ... WEnd The first parameter of _FileWriteToLine is supposed to be the file path and name, what is in the first line of C:\Windows\pyth\transf.bat? Also, the following 2 lines are wrong. FileOpen($newbatch, 0) FileWrite($newbatch, $line2 & @CRLF) The FileOpen opens the file in read mode, the second one writes to the file. The FileOpen isn't even needed because it returns a handle which you don't use anywhere. Then, you try to close $newbatch, but can't the way it's written, because you're using the file path and name, and not the handle returned from the FileOpen, so it's doing nothing, and you deleted the file 4 lines prior, so I'm not sure what exactly you THINK you're doing, but whatever it is isn't in the code you posted. Explain what it is you're trying to do with the FileReads and Writes, what's in the batch files you think you're reading from, etc. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Cyborg5000 Posted May 7, 2018 Author Share Posted May 7, 2018 The batch1 is created for python + sdk commandline to execute, based on GUI, the user will fill diff sections and the script creates the python command-line (batch1 file) at the backend. now instead of making the script run a single batch1 (parallel) (filled with command by command) iam trying to make another batch, by reading the 1st line of the batch1, create asking autoit to create a new batch 2 once batch 2 is executed, i need to have it deleted and also the line 1 command from the batch1 and make it loop till batch1 has no command left......and then exit Link to comment Share on other sites More sharing options...
Cyborg5000 Posted May 23, 2018 Author Share Posted May 23, 2018 Loop isnt working....it leaves a blank line instead of getting below lines pushed to line 1.... Global $newbatch = ("C:\Windows\pyth\bat\trans.bat") While 1 Global $readfile = FileOpen("C:\Windows\pyth\transf.bat", 0) FileOpen($newbatch, 0) Global $line1 = FileReadLine($readfile, 1) If @error = -1 Then ExitLoop ; end of file, nothing to read left, now exit.... MsgBox(0, "Reading main batch", $line1, "", "") FileWrite($newbatch, $line1 & @CRLF) _FileWriteToLine("C:\Windows\pyth\transf.bat", 1, "", True) FileClose($readfile) Sleep(1000) MsgBox(0, "Executing single batch", FileReadLine($newbatch, 1), "", "") ShellExecute("trans.bat", "", "C:\Windows\pyth\bat\", "") Sleep(1000) FileClose($newbatch) FileDelete($newbatch) WEnd Link to comment Share on other sites More sharing options...
Bilgus Posted May 23, 2018 Share Posted May 23, 2018 I think this is approximately what you are trying for? #include <FileConstants.au3> #include <File.au3> Global $sSrcBat = "C:\Windows\pyth\bat\transf.bat" Global $sDestBat = "C:\Windows\pyth\bat\trans.bat" Global $sLineText Global Const $iLine = 1 ConsoleWrite($sSrcBat & " , Exists: " & FileExists($sSrcBat) & @CRLF) While FileExists($sSrcBat) $sLineText = FileReadLine($sSrcBat, $iLine) If @error <> 0 Then ConsoleWrite("EOF" & @CRLF) ExitLoop ; end of file, nothing to read left, now exit.... Endif MsgBox(0, "Reading main batch", $sLineText) ;Put First line of src into dest FileWrite($sDestBat, $sLineText & @CRLF) ;Remove the First line from src _FileWriteToLine($sSrcBat, $iLine, "", True) Sleep(1000) MsgBox(0, "Executing single batch", FileReadLine($sDestBat, 1), "", "") ShellExecute($sDestBat, "", "", "") Sleep(1000) FileDelete($sDestBat) WEnd Link to comment Share on other sites More sharing options...
Cyborg5000 Posted May 23, 2018 Author Share Posted May 23, 2018 it still leaves out a blank line on the tranf.bat....after _FileWriteToLine($sSrcBat, $iLine, "", True) Link to comment Share on other sites More sharing options...
Bilgus Posted May 23, 2018 Share Posted May 23, 2018 Are you expecting it to delete $sSrcBat when it is empty? I verified it eats all lines in the $sSrcBat it leaves an empty file read 0 bytes Link to comment Share on other sites More sharing options...
Bilgus Posted May 23, 2018 Share Posted May 23, 2018 If you want $sSrcFile to be deleted then after wend you need something like this... ;;;WEND If FileGetSize($sSrcBat) = 0 Then FileDelete($sSrcBat) Check that size is 0 first just in case it got here through an error... 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