Jump to content

Appending data to a file


Recommended Posts

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?

 

Link to post
Share on other sites
  • Developers

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

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 post
Share on other sites

@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
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....

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...