Sign in to follow this  
Followers 0
Torque

Writing in a TXT file

12 posts in this topic

Hello all,

I'm a newbie and I try to understand scripting in autoIt but I still need help.

I try to write a few lines of text in a TXT file before the output of a binary (Doshashcalc.exe).

FileOpen ($SOfile , 1)
FileWriteLine ($SOfile , "Résultat du calcul à l'aide du programme Hashcalc:")
RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & $SOfile , "." , @SW_HIDE)
FileWriteLine ($SOfile , "Fin du processus de calcul")
FileClose ($SOfile)

This code doesn't work because the output of the binary, erases the first lines of the text file.

Is there a way to keep the first lines at the begining of the file ? :)

Share this post


Link to post
Share on other sites



Hello all,

I'm a newbie and I try to understand scripting in autoIt but I still need help.

I try to write a few lines of text in a TXT file before the output of a binary (Doshashcalc.exe).

FileOpen ($SOfile , 1)
FileWriteLine ($SOfile , "Résultat du calcul à l'aide du programme Hashcalc:")
RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & $SOfile , "." , @SW_HIDE)
FileWriteLine ($SOfile , "Fin du processus de calcul")
FileClose ($SOfile)

This code doesn't work because the output of the binary, erases the first lines of the text file.

Is there a way to keep the first lines at the begining of the file ? :)

Jdeb just made an example similar to this here: http://www.autoitscript.com/forum/index.ph...ndpost&p=160854

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hello all,

I'm a newbie and I try to understand scripting in autoIt but I still need help.

I try to write a few lines of text in a TXT file before the output of a binary (Doshashcalc.exe).

FileOpen ($SOfile , 1)
FileWriteLine ($SOfile , "Résultat du calcul à l'aide du programme Hashcalc:")
RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & $SOfile , "." , @SW_HIDE)
FileWriteLine ($SOfile , "Fin du processus de calcul")
FileClose ($SOfile)

This code doesn't work because the output of the binary, erases the first lines of the text file.

Is there a way to keep the first lines at the begining of the file ? :)

Try this...

FileOpen ($SOfile , 1)

FileWriteLine ($SOfile , "Résultat du calcul à l'aide du programme Hashcalc:")

RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & @TempDir & "\DosHashCalc.txt", "." , @SW_HIDE)

RunWait(@ComSpec & " /c & "Type " & @TempDir & "\DosHashCalc.txt" & " >> " & $SOfile, ".", @SW_HIDE)

FileWriteLine ($SOfile , "Fin du processus de calcul")

FileClose ($SOfile)

Edit: Smoke_N type faster than me...

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Thank you for your very quick answer to my question Danny35d and SmOke_N.

I worked with your help on my script and here's the result :

FileOpen ($SOfile , 1)
FileWriteLine ($SOfile , "Résultat du calcul à l'aide du programme DosHashcalc:")
RunWait (@ComSpec & " /c " & "bin\DosHashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & @TempDir & "\transit.txt", "." , @SW_HIDE)
$trans1 = FileRead (@TempDir & "\transit.txt", 200)
FileWrite ($SOfile, $trans1)
FileWriteLine ($SOfile , "Fin du processus de calcul")
FileClose ($SOfile)

It works ! But with only the first 200 characters of the transit.txt file. :mellow:

In fact I don't know how to make the FileRead function read the whole file instead of a fixed number of characters. :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you for your very quick answer to my question Danny35d and SmOke_N.

I worked with your help on my script and here's the result :

FileOpen ($SOfile , 1)
FileWriteLine ($SOfile , "Résultat du calcul à l'aide du programme DosHashcalc:")
RunWait (@ComSpec & " /c " & "bin\DosHashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & @TempDir & "\transit.txt", "." , @SW_HIDE)
$trans1 = FileRead (@TempDir & "\transit.txt", 200)
FileWrite ($SOfile, $trans1)
FileWriteLine ($SOfile , "Fin du processus de calcul")
FileClose ($SOfile)

It works ! But with only the first 200 characters of the transit.txt file. :mellow:

In fact I don't know how to make the FileRead function read the whole file instead of a fixed number of characters. :)

Do you have to use the RunWait() that your using, if so, what is the purpose... If not, why/where did you get this from out of curiousity?

Sorry... FileRead was a question:

FileRead('FilePath', FileGetSize(FilePath))
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Do you have to use the RunWait() that your using, if so, what is the purpose... If not, why/where did you get this from out of curiousity?

Sorry... FileRead was a question:

FileRead('FilePath', FileGetSize(FilePath))
:) Thank you again SmOke_N,

Now it works perfectly with different files sizes.

In fact a friend of mine helped me to create the original program.

This little piece of code is coming from a tool I use to compute Tiger hashes.

I need to run an external program to compute simultaneously several hashes on files larger than 2 Gb so it can take a lot of time.

I don't want that the process stopped before the end of the files ... (it can be difficult to know if you miss something afterwards when you have thousands of hashes).

I appreciate a lot your availability.

Torque

Share this post


Link to post
Share on other sites

Should

RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & $SOfile , "." , @SW_HIDE)

be

RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " >> " & $SOfile , "." , @SW_HIDE)

The double >> concatenates (adds) the results of Doshashcalc.exe to the end of the file, rather than creates a new one.

Couldn't you do this with a batch file, using FOR, ECHO, >>, and parameter passing?

Share this post


Link to post
Share on other sites

Should

RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " > " & $SOfile , "." , @SW_HIDE)

be

RunWait (@ComSpec & " /c " & "bin\Doshashcalc.exe" & " -rz " & cquote(GuiCtrlRead($sdir)) & " >> " & $SOfile , "." , @SW_HIDE)

The double >> concatenates (adds) the results of Doshashcalc.exe to the end of the file, rather than creates a new one.

Couldn't you do this with a batch file, using FOR, ECHO, >>, and parameter passing?

Unfortunatly, the double >> doesn't work in my case (the output of Doshashcalc does not appear in the log file) and I don't know how to make such a batch file.

Share this post


Link to post
Share on other sites

FileRead('FilePath')

This works too, as the second parameter is optional.

Keep in mind when your talking to folks, you can't assume they have Beta, the second parameter even though it says 'optional', may in fact not be.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Keep in mind when your talking to folks, you can't assume they have Beta, the second parameter even though it says 'optional', may in fact not be.

:"> Heh, I really should think of that more, I guess I don't realize how deeply having beta can affect a script. Oh and thanks for not being :) .

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
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
Sign in to follow this  
Followers 0