NEOhidra

Appending data to a file

4 posts in this topic

Looks like i am missing something. Why 

Quote

Run(@ComSpec & " /c tasklist >> processes.txt", "")

from this example

#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <File.au3>

$data = @YEAR &'.'& @MON &'.'& @MDAY &' '& @HOUR &':'& @MIN &':'& @SEC

FileOpen ( "processes.txt", $FO_OVERWRITE )
FileWriteLine ( 'processes.txt', '-=-=-=-=-=- ' & $data & ' -=-=-=-=-=-' )
FileClose ( "processes.txt" )
Run(@ComSpec & " /c dir >> output.txt", "")
Run(@ComSpec & " /c tasklist >> processes.txt", "")
Run(@ComSpec & " /c tasklist >> processes1.txt", "")
MsgBox(0, "Message", "Done")

doesnt work, while

Quote

Run(@ComSpec & " /c dir >> output.txt", "")

and

Quote

Run(@ComSpec & " /c tasklist >> processes1.txt", "")

function just fine?

 

Share this post


Link to post
Share on other sites



The fileclose() is wrong and doesn't do anything!

You need to save the Filehandle from FileOpen in a variable and use that with FileClose(). Check the Helpfile for the details.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Jos

Thank you for the hint!

I was wondering why this:

#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <File.au3>

$data = @YEAR &'.'& @MON &'.'& @MDAY &' '& @HOUR &':'& @MIN &':'& @SEC

FileOpen ( "processes.txt", $FO_OVERWRITE )
FileWriteLine ( 'processes.txt', '-=-=-=-=-=- ' & $data & ' -=-=-=-=-=-' )
FileClose ( "processes.txt" )
Run(@ComSpec & " /c tasklist >> processes.txt", "")

works?

Edited by NEOhidra

Share this post


Link to post
Share on other sites

try this:

#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <File.au3>

$data = @YEAR & '.' & @MON & '.' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC

$hMyFileHandle = FileOpen(@ScriptDir & "\processes.txt", $FO_OVERWRITE)
FileWriteLine($hMyFileHandle, '-=-=-=-=-=- ' & $data & ' -=-=-=-=-=-')
FileClose($hMyFileHandle)
RunWait(@ComSpec & " /c dir >> " & @ScriptDir & "\processes.txt", "", @SW_HIDE)
RunWait(@ComSpec & " /c tasklist >> " & @ScriptDir & "\processes.txt", "", @SW_HIDE)
; Run(@ComSpec & " /c tasklist >> processes1.txt", "") ; <--- do you want write to a new file ??

ShellExecute(@ScriptDir & "\processes.txt")

MsgBox(0, "Message", "Done")

..... as Jos already sayd ..... Check the Helpfile for the details... :)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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