Sign in to follow this  
Followers 0
huskies

FileRead last line Windows 7

6 posts in this topic

Hi I have an easy yet complicated question that's been plaguing me.

A little background on the info, I'm trying to automate some putty commands in our datawarehouse. After some reading on the forums, I found that putty has a log function so I decided to use that as a way to control putty

Putty can log everything from the cmd into txt file, so when the txt file says "login as:" I want to send in my username etc

I tried Fileopen forthe log file but failed, and according to some posts, fileopen is troublesome with windows 7. So I tried

$file = ShellExecute($file)
msgbox (1,"1", FileReadLine ($file,-1))

and got nothing,

Another post suggested using _FileReadToArray()because it doesn't lock the file that you opened.

But what I need to do with _FileReadToArray($path,$content) is just read the LAST line of the file, and there were no documentation that described how to do that. Can someone help me out with this please?

Also I heard that using plink may potentially solve this problem, but I would really like to use this method, since I need to read some of the actual data from the log file as well.


<It Shall Be Done>

Share this post


Link to post
Share on other sites



not sure if this would work, didn't try it, but you could try it.

$i=0
$t=0
$var = _filereadtoarray($path, $content)
for $i=1 to $var[0]
    $t += 1
    If $i = $var[0] Then MsgBox(0, "", $var[$t])
Next
Exit

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

Exactly why do you feel that FileOpen is problematic under Seven?

Why can't you just use this one-liner:

Local $str = FileReadLine($file, -1)


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

If FileOpen() fails to open the file for read, then I would expect FileReadLine() to also fail. When you use FileReadLine() without using FileOpen(), then FileReadLine() does a file open, file read and file close, all in the same function call. I would also expect _FileReadToArray() to fail also as it does use FileOpen(), FileRead() and FileClose(). The issue is why the file seems to be locked. I can guess that Putty is locking the file and AutoIt can not open it for read but I have been incorrect before.

Are you using the latest version of AutoIt? As IIRC, AutoIt did have some issues with file opening and sharing the file with other programs at the same time in some of AutoIts previous versions. Try the latest version if you are not using it already.

Share this post


Link to post
Share on other sites

Hi I have an easy yet complicated question that's been plaguing me.

A little background on the info, I'm trying to automate some putty commands in our datawarehouse. After some reading on the forums, I found that putty has a log function so I decided to use that as a way to control putty

Putty can log everything from the cmd into txt file, so when the txt file says "login as:" I want to send in my username etc

I tried Fileopen forthe log file but failed, and according to some posts, fileopen is troublesome with windows 7. So I tried

$file = ShellExecute($file)
msgbox (1,"1", FileReadLine ($file,-1))

and got nothing,

Another post suggested using _FileReadToArray()because it doesn't lock the file that you opened.

But what I need to do with _FileReadToArray($path,$content) is just read the LAST line of the file, and there were no documentation that described how to do that. Can someone help me out with this please?

Also I heard that using plink may potentially solve this problem, but I would really like to use this method, since I need to read some of the actual data from the log file as well.

Without reading the words surrounding the code you posted I just want to say that the code is bloody bullox.

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Hi everyone, thanks for the enthusiastic replies.

1. I do have the latest version of AutoIt fortunately.

2. my included code looks aweful because this is just a feasibility test .

3. To address the fileopen issue, here is my code

$file = fileopen("C:\Users\Robert\Desktop\putty.log",0)

Local $str = FileReadLine($file, -1)

and actually got something. So I guess it was just a visibily issue, I assumed that because I can't see it then it's not there.

4. I did a test and filereadline was able to read as the file is getting updated without the need to fileclose. So my question is can I just use fileopen and Filereadline or is it better practice to use _FileReadToArray($path,$content)


<It Shall Be Done>

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