Print to console/command prompt - windows

I want to write text to console/Windows command prompt in AutoIt. I made a test script as shown below:
Func Test()
ConsoleWrite("Hello")
EndFunc
Test()
I saved the script as test.au3. When I run it, it does not print to console. I checked ConsoleWrite(); it should print to DOS console if it the script is compiled as a console application.
I compiled the script using Aut2Exe. It still does not print to console. How do I write to console in AutoIt?

You can also add the following compiler switch to the top of your script:
#pragma compile(Console, True)

Just compile your test.au3 like this:
%PathToAutoItVersion%\Aut2Exe\Aut2exe.exe /in test.au3 /out test.exe /console
And then you can Run test.exe and it will print out:
hello

How do I write to console in AutoIt?
As per Documentation - Function Reference - ConsoleWrite() :
The purpose for this function is to write to the STDOUT stream. … Scripts compiled as Console applications also have a STDOUT stream.
Save script as .au3 file, then:
press F5 (Tools > Go) in editor. Console output will be displayed in the editor's lower pane:
or press Ctrl + F7 (Tools > Compile), enable Create CUI instead of GUI EXE., then click Compile Script and run the resulting executable.
or add #AutoIt3Wrapper_Change2CUI=Y (or #pragma compile(Console, True)) to top of script, then press F7 (Tools > Build) and run the resulting executable.
or execute:...\AutoIt3\Aut2Exe\Aut2exe.exe /in ...\script.au3 /out ...\script.exe /consoleand run the resulting executable.
I compiled the script using Aut2Exe. It still does not print to console.
For compiled scripts a console window is visible during runtime only. Example:
#AutoIt3Wrapper_Change2CUI=Y
Global Enum $EXITCODE_OK
Global Const $g_sMsg = 'Hello, World!' & #CRLF
Global Const $g_iDelay = 1000 * 10
Main()
Func Main()
ConsoleWrite($g_sMsg)
Sleep($g_iDelay)
Exit $EXITCODE_OK
EndFunc
Related: Console and graphical user interface.

Related

DOORS make console the interactive window

Is there any way to tell DOORS to use the current command prompt window as the interactive window when executing in batch mode?
For example, if I have hello.dxl which looks like
print("Hello world")
and Run.bat which looks like
"C:\Program Files\IBM\Rational\DOORS\9.6\bin\doors.exe" -u test -pass testPass -b hello.dxl -W
It currently opens a new window, prints "Hello World" and then closes the window (it closes it because of the -W). Is there any way to redirect this output to the command prompt window that was opened to run the batch file?
There is no console variant of doors.exe and as far as I know there is no possibility to give a sort of handle to a specific prompt window and use e.g. OLE Automation to print to this window, so, basically, no, it's not possible.
A workaround that we use for this requirement is to have a batch file which
generates the name to a temporary file ,
passes this file to DOORS as a parameter (using environment variables)
make DOORS/DXL cout to this file
after the DXL has finished, type the content of the temporary file in the calling batch and optionally delete it.
PS: according to https://www.ibm.com/mysupport/s/question/0D50z00006HIM4oCAH/doors-print-redirect-tutorial-for-print-cout-and-logfiles it apparently used to be possible to redirect STDOUT/STDERR to a specific file, but not in recent DOORS versions.

in golang,how can keep console window open when the program is done which startup the exe by double click

in windows when startup by double click the .exe
and when the programe is done by os.Exit(...)
so,is there anyway to keep the console window open,just like auto run an cmd command.
I dontn want some solution with some PAUSE or some others thing to let it wait close.I need completed exit the program,and keep the console window .
BTW,I think some way of open another console window,but fail with this code
c :=exec.Command("start")
if err := c.Run(); err != nil {
fmt.Println("Error: ", err)
}
os.Exit(0)
If you need the program to exit completely, but keep the window open, run the program from a console.
win+r
type cmd
enter
navigate to the folder you have the binary in, by using cd myFolder to move into a folder, and cd .. to move one folder up
run the binary by typing ./myBinary.exe and pressing enter
binary finishes running, and console stays open.
EDIT:
To be able to double-click, using pause in a batch-file is the simplest solution:
launch.bat
./myBinary.exe
pause
save in same folder as binary, and double-click to run.
You could write a program in a language of your choice that does the same thing as that batch file, if you really want to.
You could call fmt.Scanf(). I know it's hack and you wouldn't want to do it in a production application, but it works.
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
fmt.Scanf("h")
}
BTW,I think some way of open another console window,but fail with this
code
If you run your_executable.exe using the cmd.exe processor using the /k option it should run the executable and also keep the console open.
cmd.exe /k your_executable.exe

Qt Creator - debug application with input from file

I usually test my app with
./myapp < test/test01.in
So in my run configuration I set the command line arguments to:
< test/test01.in
Now, when I launched the debug session, I came across the following error:
Debugging complex shell commands in a terminal is currently not supported.
Can I debug my app in QtCreator without having to type all the input by hand/copying it directly into the terminal?
You need correctly fill Projects->Run fields ("Executable", "Command line arguments", "Working directory") and left "Run in terminal" checkbox in unchecked state.
After that you can start debugging(F5).

Boost.Asio object_handle doesn't wait for stdin when debugging

I am trying to use Boost.Asio's object_handle to wait for input from the console:
int main()
{
using namespace boost::asio;
io_service io;
windows::object_handle in(io);
in.assign(::GetStdHandle(STD_INPUT_HANDLE));
in.wait();
io.run();
return 0;
}
This works if I run it from the terminal, but when I try to debug into it with Visual Studio it skips wait(). What's going on?
A windows console application can create it's own console, or it can attach to an existing console (e.g. the parent command shell). This is likely what creates the difference.
You can influence the console allocation usually with things like start cmd /c myprog vs. ``start /b cmd /c myprog`, or you can explicitly create you console
The MSDN article that has the backgrounds and APIs is here:
Creation of a Console

Gambit Scheme: gsi and gsc windows closes after end!

I'm experimenting with Gambit scheme and I have problem! My OS is Windows 7.
When I try to interpret script I do:
gsi.exe myscript.scm
This works, but GSI's console window is shown and closed just after script finished. I can't see results my program prints! I may do (read-line) at the end, but... when I try to compile with GSC.exe the behaviour is the same: it opens console window, does something, prints about errors and closes it immediately - I can't read something! In this case I can't even do (read-line) hack, you see. How can I view what Gambit writes?
This doesn't works, though:
gsc.exe 1.scm > 1.txt
You should run Gambit in an existing terminal window. Open up your terminal first, and then run Gambit. When Gambit terminates, your terminal will be still up.
Create a batch file with the commands. Set the properties on the batch file such that the window doesn't close after executing(right click, properties on the batch file's icon).
You can always, add "pause" at the end of the bath file, to keep the window open.
Alternatively, just open a DOSBOX box, and run the script from there. The box will remain open when the scrip completes.
UPDATE
terminal
To open a terminal(Command Prompt, DOS Box,etc.) use the [Start] button. Enter cmd in the "Run" field.
This will open a terminal with a command line interpreter. You can run gsc or gsi from there.
batch files
Here is the sample program hello.scm:
(display "HELLO WORLD")
(newline)
Method 1--using pause. This example is only for calling binary executable(.EXE) files such as gsc, or gsi.exe:
#echo off
gsi hello.scm
pause
Method 2--using cmd /k. The pause method (above) is preferred as this starts another cmd shell:
#echo off
cmd /k gsi hello.scm
properties
Sorry, setting the "Close on exit" property of a command apparently only exists for true DOS commands via .pif files.
To the same end right-click hello.scm, then associate it with cmd /k gsi hello.scm.
Any of the above batch files may be modified to take a filename argument (as %1, or %* for all args) and run gsc %1 instead of gsc hello.scm. After making the batch file generic in this way, associate the .SCM extension with it.
Associate .SCM with run-gsi.bat:
#echo off
gsi %*
pause

Resources