Piotr12

Writing to cmd

27 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

@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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

Of course not. That was simplification. I want .bat-like echo command.

Share this post


Link to post
Share on other sites

#4 ·  Posted

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted

2 minutes ago, JLogan3o13 said:

If you then compile the script

I'm looking for a scripting language. Compiling defeats it's purpose...

Share this post


Link to post
Share on other sites

#6 ·  Posted

Then stick with batch and it's many limitations. Or go with powershell


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted

That's why I wanted to confirm.

BTW, why such limitation?

Share this post


Link to post
Share on other sites

#8 ·  Posted

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#10 ·  Posted

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. 

 

 

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

Share this post


Link to post
Share on other sites

#13 ·  Posted

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

Share this post


Link to post
Share on other sites

#14 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted

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.

Share this post


Link to post
Share on other sites

#16 ·  Posted

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.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#18 ·  Posted

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?

Share this post


Link to post
Share on other sites

#20 ·  Posted

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.

Share this post


Link to post
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