kgk Posted August 7, 2008 Share Posted August 7, 2008 I cant get this working after updating autoit from version 3.0.9.0 to newest version RunWait ( @comspec & " /c .\bin\commandline.exe -v" & " >> " & quote($logfile) ) I also tried this : RunWait (@ComSpec & " /c " & " .\bin\commandline.exe -v >> " & ($logfile) It does work when I use this instead a variable : RunWait (@ComSpec & " /c " & " .\bin\sha1deep.exe -v >> " & "logfile.txt" ) $logfile does print correct to a msg box when I do this : msgbox ( 16 , "LOGFILE " & $logfile , $logfile ) Anyone know what the problem here is? thnx KGK Link to comment Share on other sites More sharing options...
picaxe Posted August 7, 2008 Share Posted August 7, 2008 This works for meRunWait (@ComSpec & " /c " & " dir >> " & $logfile)using AutoIt v3.2.12.1 Link to comment Share on other sites More sharing options...
kgk Posted August 7, 2008 Author Share Posted August 7, 2008 (edited) This works for meRunWait (@ComSpec & " /c " & " dir >> " & $logfile)using AutoIt v3.2.12.1 ? Hmm strange I tried your exact code as you typed it. And on my machine logfie gets created but is empty. Im using 3.2.12.1 also. I created a smaller test script here is the complete code of it : $version = "1" $logdir = FileSelectFolder ( "Choose log dir" & @CRLF & "Logdir need to be writable" , -1 , 1 ) if not fileexists ($logdir) then exit $testfile = fileopen ( $logdir & "\testfile" , 1 ) fileclose ( $testfile ) filedelete ( $testfile ) $logfile = $logdir & "\" & "logfile.txt" fileopen ( $logfile , 1 ) if $logfile = -1 then msgbox ( 16 , "Logger " & $version , "Can't write logfile here" ) exit endif fileclose ( $logfile) RunWait (@ComSpec & " /c " & " dir >> " & $logfile) msgbox ( 16 , "LOGFILE " & @AutoItVersion , $logfile ) The above gives me a empty logfile.txt in the directory I choose. Edited August 7, 2008 by kgk Link to comment Share on other sites More sharing options...
picaxe Posted August 7, 2008 Share Posted August 7, 2008 (edited) Try this $version = "1" $logdir = FileSelectFolder("Choose log dir" & @CRLF & "Logdir need to be writable", -1, 1) If Not FileExists($logdir) Then Exit If StringRight($logdir, 1) <> "\" Then $logdir &= "\" $file = "testfile" $testfile = FileOpen($logdir & $file, 1) ConsoleWrite("FileHandle=" & $testfile & @LF) FileClose($testfile) ConsoleWrite("testfile=" & $logdir & $file & @LF) FileDelete($logdir & $file) $logfile = "logfile.txt" $hLog = FileOpen($logdir & $logfile, 1) If $hLog = -1 Then MsgBox(16, "Logger " & $version, "Can't write logfile here") Exit EndIf FileClose($hLog) RunWait(@ComSpec & " /c " & " dir >> " & $logfile, $logdir) MsgBox(16, "LOGFILE " & @AutoItVersion, $logfile) Edited August 7, 2008 by picaxe Link to comment Share on other sites More sharing options...
ResNullius Posted August 7, 2008 Share Posted August 7, 2008 (edited) ? Hmm strange I tried your exact code as you typed it. And on my machine logfie gets created but is empty. Im using 3.2.12.1 also. I created a smaller test script here is the complete code of it : $version = "1" $logdir = FileSelectFolder ( "Choose log dir" & @CRLF & "Logdir need to be writable" , -1 , 1 ) if not fileexists ($logdir) then exit $testfile = fileopen ( $logdir & "\testfile" , 1 ) fileclose ( $testfile ) filedelete ( $testfile ) $logfile = $logdir & "\" & "logfile.txt" fileopen ( $logfile , 1 ) if $logfile = -1 then msgbox ( 16 , "Logger " & $version , "Can't write logfile here" ) exit endif fileclose ( $logfile) RunWait (@ComSpec & " /c " & " dir >> " & $logfile) msgbox ( 16 , "LOGFILE " & @AutoItVersion , $logfile ) The above gives me a empty logfile.txt in the directory I choose.In this example $logfile ends up as a string and your last FileClose() call tries using it instead of a filehandle as in your test with $testfile. FileClose() must use a filehandle. So what's happening is your logfile isn't being closed when you try to pipe to it. Use the " /k" option in your RunWait() line instead of " /c" and you will see the error from the comand prompt about the file being in use. Here's a corrected version: $version = "1" $logdir = FileSelectFolder ( "Choose log dir" & @CRLF & "Logdir need to be writable" , -1 , 1 ) if not fileexists ($logdir) then exit $testfile = fileopen ( $logdir & "\testfile" , 1 ) fileclose ( $testfile ) filedelete ( $testfile ) $logfile = '"' & $logdir & "\" & "logfile.txt" & '"' $fhLogFile = fileopen ( $logfile , 1 ) if $fhLogfile = -1 then msgbox ( 16 , "Logger " & $version , "Can't write logfile here" ) exit endif fileclose ($fhLogFile) RunWait (@ComSpec & " /c " & " dir >> " & $logfile ) msgbox ( 16 , "LOGFILE " & @AutoItVersion , $logfile ) Note the use of $fhLogFile being the use of the filehandle to $logfile. Also note that I wrapped the string definition for $logfile = in quotes so if somebody chooses a folder with a space in the path (like My Documents) the dos command will still execute properly. Edit: picaxe kinda beat me to it. I've gotta stop starting replies and then getting sidetracked! Note picaxe set the working dir for the RunWait() line which eliminates the need to wrap the $logfile string in quotes. Edited August 7, 2008 by ResNullius Link to comment Share on other sites More sharing options...
kgk Posted August 8, 2008 Author Share Posted August 8, 2008 Awsome thnx for the help Guys I will go and try that 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