Jump to content

Writing to cmd


Recommended Posts

Hi, 

I'd like to confirm: I can't simply start my script from a cmd and have it print something there? That is, open notepad++, write two-liner script and just run it?

Because yesterday I was like "hurray, finally scripting language on Windows I can use", and today after 10 minutes of trying to print to console I was like "ok, uninstalling".

Link to comment
Share on other sites

  • Moderators

@Piotr12 Your question, based on your title is a bit confusing. Are you saying you want to write the script and run it without having AutoIt installed?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

It is difficult to surmise what you are trying to do without seeing your code. In its infancy, you could create a script like so:

WinActivate("[ConsoleWindowClass]", "")
Send("Testing")

If you then compile the script, open a cmd window and call it, it will activate the cmd window and then write a simple line to it. If you're looking for a way to print out more complex responses to commands, probably your best bet is to explain precisely what you're looking to accomplish. There is likely an easier way.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

You can run AU3 scripts uncompiled, of course. I don't see the ability to compile to a stand alone executable for portability to be a limitation. As I mentioned, the limitation (in my humble opinion) is being imposed by you as wanting to open from cmd and write to cmd. AutoIt has its own console, to which you can easily write to and read from, and many other logging abilities - you're just limiting your thinking to batch. If you would explain in detail what you're attempting, and what info you need to see, I am sure we can show you an easy way to do it with AutoIt

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Piotr12, just look at the help manual for how to run an AutoIt script...

Running Scripts
 

No need to compile.  Just write your myscript.au3 in whatever you want and go to command line and run it.

Also, just use the ConsoleWrite() function to output text to the console session.

Edited by cbruce
added output option
Link to comment
Share on other sites

2 minutes ago, JLogan3o13 said:

If you would explain in detail what you're attempting, and what info you need to see, I am sure we can show you an easy way to do it with AutoIt

I want to have something like bash on windows (without bash). I want to automate various small developer tasks. I want to have a script which will compare performance of several different programs. Or recursively delete files matching specific pattern. Or do some text search/grep/etc. Or using it for some job in jenkins. Sky is the limit ;) 

For all of this, I must have ability to quickly cook up a couple lines of code, have it in a file, and execute it. By "clicking" it from total commander. Or executing from command line. Or from another script. 

 

 

 

Link to comment
Share on other sites

  • Developers

Do you maybe mean you want a Console App that can write output to it using ConsoleWrite() ? -> Yes

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

No. I want something simple and quick. Even with powershell you can do powershell "& ./script.ps1". And it writes output to cmd it was run from. If I want to, I can redirect it to a file. But I don't have to. I don't have to use any special tool to run it. Just the interpreter. I can probably do sth like powershell -c "command1; command2" (a guess). Too bad it's syntax is broken (IMO).

Link to comment
Share on other sites

  • Developers
6 minutes ago, Piotr12 said:

Too bad it's syntax is broken

What is broken? 

6 minutes ago, Piotr12 said:

I want something simple and quick.

How can something so simple and quick be explained is such a  "clear as mud" way? ;) 
The question to me is indeed simple: Do you want to interact with the STDIN/STDOUT/STDERR of a shelled program or simply like I stated want to send text to the STDOUT and it appear in the CMD session?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Also, Piotr12... In PowerShell you have to use Write-Output or Write-Host to get your text to show up in the console and/or be able to be redirected.  AutoIt's ConsoleWrite() function gives you the same capability from an autoit script.

Link to comment
Share on other sites

10 minutes ago, cbruce said:

Again, Piotr12... AutoIt runs its scripts from the command line JUST LIKE YOUR PowerShell example.  Just refer to the help link I provided above.

How do I print to cmd window the script was started from?

 

9 minutes ago, Jos said:

What is broken? 

powershell syntax.

 

9 minutes ago, Jos said:

The question to me is indeed simple: Do you want to interact with the STDIN/STDOUT/STDERR of a shelled program or simply like I stated want to send text to the STDOUT and it appear in the CMD session?

The later.

 

4 minutes ago, cbruce said:

Also, Piotr12... In PowerShell you have to use Write-Output or Write-Host to get your text to show up in the console and/or be able to be redirected.  AutoIt's ConsoleWrite() function gives you the same capability from an autoit script.

When I had script with ConsoleWrite("HElloWorld") and executed it from cmd e.g. AutoIt3.exe myscript.au3, nothing was printed.

Link to comment
Share on other sites

  • Developers

When the question is for AutoIt3, you need to compile the script as Console which is an au2exe option. This option is configurable with #PRAGMA.
When you want to AutoIt3 to interact with the STDxx, you can use the available STD* functions for that. 

Jos :)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 minute ago, Jos said:

When the question is for AutoIt3, you need to compile the script as Console :)

Thanks, that I wanted to confirm. For me, that's the show stopper.

So for curiosity sake, why such limitation?

Link to comment
Share on other sites

Piotr12, I'm guessing you launched "AutoIt.exe myscript.au3" from Windows RUN or from Windows Explorer.  Either one of those would have launched a Command Prompt window to run the AutoIt command and your script, but then immediately closed that window unless you had added a Sleep() or a loop with an _IsPressed() that was looking for an ESC key, or something in order to keep the command Prompt open long enough to see your output.

Also, if you launch a Command Prompt window first and then run your AutoIt script from that command line... you will see the output because that Command Prompt window will not close until you exit it manually.

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...