Willow Posted March 10, 2012 Posted March 10, 2012 I am struggling to output an "ipconfig /all" to a text file where the file path has a space in it. I know that it is probably just the proper placement of quotes for the path but I cannot get it... The first line of the sample code creates the folder. The second line then runs the ipconfig /all and in theory, saves it to the newly created folder as a text file. Therein lies the problem. I cannot get the text file to be created in the folder due to the space between "pc inventory" no matter what quote placement I use(d). DirCreate("c:\pc inventory\"& @MON & "\pc1") Run("cmd /c ipconfig /all" > "c:\pc inventory\"& @MON & "\pc1\ip.txt") Thanks in advance.
DW1 Posted March 10, 2012 Posted March 10, 2012 (edited) You were right, just placement of quotes. You want to double quote the parameter with a space in it. If we need to pass double quotes (there are many ways to do this) I prefer to start with a single quote. DirCreate("c:pc inventory"& @MON & "pc1") Run('cmd /c ipconfig /all > "c:pc inventory'& @MON & 'pc1ip"') EDIT: Explanation To test these things in the future, it's easy enough to place the parameter in a message box. If you put your string in a message box: MsgBox(0,'Test', "cmd /c ipconfig /all" > "c:pc inventory"& @MON & "pc1ip.txt") you will find that it returns "True" because the way you placed the quotes is saying "cmd /c ipconfig /all" MORE THAN "c:pc inventory"& @MON & "pc1ip.txt". If you were to fix the string to put the ">" inside the quotes, you would have MsgBox(0,'Test', "cmd /c ipconfig /all > c:pc inventory"& @MON & "pc1ip.txt") which returns: cmd /c ipconfig /all > c:pc inventory03pc1ip.txt notice the lack of quotes. What we wanted to see was cmd /c ipconfig /all > "c:pc inventory03pc1ip.txt" So I picked one of many ways to add the double quotes in the right spot; MsgBox(0,'Test', 'cmd /c ipconfig /all > "c:pc inventory'& @MON & 'pc1ip"') which returns: cmd /c ipconfig /all > "c:pc inventory03pc1ip" Edited March 10, 2012 by danwilli AutoIt3 Online Help
Willow Posted March 10, 2012 Author Posted March 10, 2012 Thanks Danwilli for the thorough explanation. Getting quotes in the right place and within syntax is an area I always struggle with...
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