Sign in to follow this  
Followers 0
breakfast

FileCountLines returning 0

7 posts in this topic

hello,

I'm new to autoit, so I'm still trying to get the hang of it. I'm trying to write a script that will analyze the output of ipconfig. my ultimate goal is to return the MAC address of wireless adapters only, but right now I'm stuck at counting the lines of the output!

Run("cmd.exe")
sleep(500)
Send("ipconfig /all > C:\lol.txt{ENTER}")
sleep(100)
WinClose("C:\WINDOWS\system32\cmd.exe")
$ipconfig = FileOpen("C:\lol.txt", 0)
 If $ipconfig = -1 Then
     MsgBox(0,"kk","Failed to open file")
 EndIf   
 $linesttl = _FileCountLines($ipconfig)
 MsgBox(0,"lol",$linesttl)

this script returns 0 in the message box. However...

$file = FileOpenDialog("What file","","Text Files (*.txt)")
$result = _FileCountLines($file)
MsgBox(0,"lol",$result)

This script returns the correct number of lines when I manually select the output generated by the first script. What am I missing?

Share this post


Link to post
Share on other sites



Your problem is that you're trying to count the lines of $ipconfig, and $ipconfig isn't the file path.. ipconfig is the command that says to open the file. Give this a shot.

Dim $file = "C:/lol.txt" ; File path
$ipconfig = FileOpen($file, 0) ; Open the file (using the file path specified above)
If $ipconfig = -1 Then
MsgBox(0,"kk","Failed to open file")
EndIf    
$linesttl = _FileCountLines($file)
MsgBox(0,"lol",$linesttl)

:)


Global $arr[2]

$arr[0]="hip"
$arr[1]="hip"
;^^ hip hip array. ^^

Share this post


Link to post
Share on other sites

hello,

I'm new to autoit, so I'm still trying to get the hang of it. I'm trying to write a script that will analyze the output of ipconfig. my ultimate goal is to return the MAC address of wireless adapters only, but right now I'm stuck at counting the lines of the output!

Run("cmd.exe")
sleep(500)
Send("ipconfig /all > C:\lol.txt{ENTER}")
sleep(100)
WinClose("C:\WINDOWS\system32\cmd.exe")
$ipconfig = FileOpen("C:\lol.txt", 0)
 If $ipconfig = -1 Then
     MsgBox(0,"kk","Failed to open file")
 EndIf   
 $linesttl = _FileCountLines($ipconfig)
 MsgBox(0,"lol",$linesttl)

this script returns 0 in the message box. However...

$file = FileOpenDialog("What file","","Text Files (*.txt)")
$result = _FileCountLines($file)
MsgBox(0,"lol",$result)

This script returns the correct number of lines when I manually select the output generated by the first script. What am I missing?

Hi,

You need to pass the path of lol.txt to _FileCountLines($sFilePath)

(using FileOpen() returns a handle not a path...

using FileOpenDialog() returns a path to the file)

Also you need to give a bigger sleep() so that cmd window gets enough time to pipe the data to the lol.txt file.

#Include <File.au3>

$ipconfig = "C:\lol.txt" 

$PID = Run("cmd.exe")
sleep(100)

Send("ipconfig /all > " & $ipconfig & "{ENTER}")
sleep(500) ; allow enough time for the cmd window to pipe the text to the file.
ProcessClose($PID)

If $ipconfig = -1 Then
     MsgBox(0,"kk","Failed to open file")
EndIf    

$linesttl = _FileCountLines($ipconfig) ; use a path to the file, not the handle
MsgBox(0,"lol",$linesttl)

Cheers

Share this post


Link to post
Share on other sites

Thanks for the correction, I guess my concept of opening files and working with them was a little off, thanks for the help! :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I would rather use Run(@Comspec & " /c ipconfig /all > " & $ipconfig, "" , @SW_HIDE)

It's more reliable than a sleep and sending the keys.

Edited by Pain

Share this post


Link to post
Share on other sites

thanks guys, your giving me some good info to learn about. I still have alot of reading to do!

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