Jump to content

Run a command and output to a file


Recommended Posts

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 by Hannes123
Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.
Link to comment
Share on other sites

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

  • 3 weeks later...

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

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

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

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.

:huh2:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...