breakfast Posted January 6, 2009 Share Posted January 6, 2009 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? Link to comment Share on other sites More sharing options...
bundyxc Posted January 6, 2009 Share Posted January 6, 2009 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. ^^ Link to comment Share on other sites More sharing options...
smashly Posted January 6, 2009 Share Posted January 6, 2009 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 Link to comment Share on other sites More sharing options...
breakfast Posted January 6, 2009 Author Share Posted January 6, 2009 Thanks for the correction, I guess my concept of opening files and working with them was a little off, thanks for the help! Link to comment Share on other sites More sharing options...
Pain Posted January 6, 2009 Share Posted January 6, 2009 (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 January 6, 2009 by Pain Link to comment Share on other sites More sharing options...
BrettF Posted January 6, 2009 Share Posted January 6, 2009 You can also use the standard i/o flags with run to read the output. Removes the need for lol.txt. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
breakfast Posted January 6, 2009 Author Share Posted January 6, 2009 thanks guys, your giving me some good info to learn about. I still have alot of reading to do! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now