Morthawt Posted May 5, 2011 Share Posted May 5, 2011 How do you run a commandline program and output the program's output to a file such as in dos where you add >output.ext to output the command's output to the said file? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
hannes08 Posted May 5, 2011 Share Posted May 5, 2011 (edited) Run(@ComSpec & " /c " & 'commandName > filename', "", @SW_HIDE) Or you can directly read from the output of that file with StdoutRead(). Just take a look at the help file. Edited May 5, 2011 by Hannes123 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Morthawt Posted May 5, 2011 Author Share Posted May 5, 2011 Run(@ComSpec & " /c " & 'commandName > filename', "", @SW_HIDE) So basically just use the same old dos technique, theres no autoit method to output? Also, rather than make a new thread.. How can I output information to the screen of a command prompt when I load a compiled script? I want to be able to make a compiled exe that can provide a user with information right there in the command prompt window and obtain input like a number menu system "push 1 for.. push 2 for..." etc. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
hannes08 Posted May 5, 2011 Share Posted May 5, 2011 So basically just use the same old dos technique, theres no autoit method to output?Also, rather than make a new thread.. How can I output information to the screen of a command prompt when I load a compiled script?I want to be able to make a compiled exe that can provide a user with information right there in the command prompt window and obtain input like a number menu system "push 1 for.. push 2 for..." etc.You can make outputs to commandline with ConsoleWrite(), but then you need to set the "Create CUI instead of GUI" option on compiling OR insert "#AutoIt3Wrapper_Change2CUI=y" on top of your script. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Morthawt Posted May 5, 2011 Author Share Posted May 5, 2011 You can make outputs to commandline with ConsoleWrite(), but then you need to set the "Create CUI instead of GUI" option on compiling OR insert "#AutoIt3Wrapper_Change2CUI=y" on top of your script.Can you explain this CUI? I dont find it in the help file. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
smartee Posted May 5, 2011 Share Posted May 5, 2011 hi, Have you checked out StdoutRead() like Hannes123 suggested? Example (from helpfile):; Demonstrates StdoutRead() #include <Constants.au3> Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($foo) If @error Then ExitLoop MsgBox(0, "STDOUT read:", $line) Wend While 1 $line = StderrRead($foo) If @error Then ExitLoop MsgBox(0, "STDERR read:", $line) Wend MsgBox(0, "Debug", "Exiting...") -smartee Link to comment Share on other sites More sharing options...
wzsmith Posted May 26, 2011 Share Posted May 26, 2011 Just found this while looking to do the same thing. Muchas Gracias for the answers. Link to comment Share on other sites More sharing options...
wzsmith Posted May 26, 2011 Share Posted May 26, 2011 Here's something weird though.... I'm trying to write a script to automate some tasks using nltest.exe, which lives inside of c:\windows\system32 $command = "nltest" Local $foo = Run(@ComSpec & " /c " & $command & " ", "c:\windows\system32\", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Does not work, I get "'nltest' is not recognized as an internal or external command" back from STDERR. Same thing you'd get if you opened up a command prompt and typed in "Ooogaboogaboogacuckapoopoo." However, I can replace "nltest" with something like "ping" or "nslookup" or pretty much any other executable that lives in the same path with no problem. It's only nltest.exe that comes back not found. The command runs fine as a normal user, but I tried compiling my script and running as an Administrator also with no luck. If I do something like $test = run("c:\windows\system32\nltest.exe"), I get a "0" back as the result. Maybe something odd with nltest.exe? Link to comment Share on other sites More sharing options...
Merrik Posted May 27, 2011 Share Posted May 27, 2011 Here's something weird though.... I'm trying to write a script to automate some tasks using nltest.exe, which lives inside of c:\windows\system32 $command = "nltest" Local $foo = Run(@ComSpec & " /c " & $command & " ", "c:\windows\system32\", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Does not work, I get "'nltest' is not recognized as an internal or external command" back from STDERR. Same thing you'd get if you opened up a command prompt and typed in "Ooogaboogaboogacuckapoopoo." However, I can replace "nltest" with something like "ping" or "nslookup" or pretty much any other executable that lives in the same path with no problem. It's only nltest.exe that comes back not found. The command runs fine as a normal user, but I tried compiling my script and running as an Administrator also with no luck. If I do something like $test = run("c:\windows\system32\nltest.exe"), I get a "0" back as the result. Maybe something odd with nltest.exe? Are you running your script within the same directory as NLTEST? If not, try it. Second, what switch are you using with NLTEST? Link to comment Share on other sites More sharing options...
wzsmith Posted May 27, 2011 Share Posted May 27, 2011 Are you running your script within the same directory as NLTEST? If not, try it. Second, what switch are you using with NLTEST?That wasn't quite it, but it got me on the right track. It seems that AutoIT was compiling for x86 by default (which is probably what I want, most of the time) but I'm running Windows 7 x64. My best guess is that nltest.exe is compiled for 64 bit and the script wasn't able to call it properly for some reason. Thanks a ton for the advice, next step is to figure out how to parse the data that comes from stdout. There must be a substring function somewhere. To the help file! Link to comment Share on other sites More sharing options...
hannes08 Posted May 29, 2011 Share Posted May 29, 2011 That wasn't quite it, but it got me on the right track. It seems that AutoIT was compiling for x86 by default (which is probably what I want, most of the time) but I'm running Windows 7 x64. My best guess is that nltest.exe is compiled for 64 bit and the script wasn't able to call it properly for some reason. Thanks a ton for the advice, next step is to figure out how to parse the data that comes from stdout. There must be a substring function somewhere. To the help file!C:\Windows\system32 on 64bit installations is for 64bit programs only. I don't think there's a problem calling a 64bit app from a 32bit compiled AutoIT script. Especially when it is located in that folder (You can just try calling it with Run("program.exe") as it should be in the global environment variable path)StringMid is the substring function you're looking for. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] 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