I want to know how it is possible to pause a console application at end and by pressing enter, it ends in assembely. here is a peice of code which shows "hello world" on screen, but it will close immediatly. So how to pause program at end?
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
.data
sConsoleTitle db "Console Application",0
sWriteText db "Hello World",0
.code
Main PROC
LOCAL hStdout :DWORD
invoke SetConsoleTitleA, offset sConsoleTitle
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hStdout,EAX
invoke WriteConsoleA, hStdout, offset sWriteText, 16d, 0, 0
invoke ExitProcess, 0
Main ENDP
end Main
Since you're already working with a console (I see stdout and WriteConsole) I'm going to suggest that you work with a proper console:
cmd.exe. Can simply be run off Start -> Run and is included with every modern Windows. Can be modified to use different fonts, resized, etc.
Windows PowerShell. Most people like it. I don't.
A terminal program like Console. Tabs, translucency and Linux-like mouse behavior are great to have.
Clicking an .exe to run it is great, but what happens if you want to supply it input? Command line parameters? What if you want to redirect stdin/stdout? What if you want to pipe a file to it, or it to another program, like grep? What if you wanted to run your program non-interactively, e.g. from a script?
It's one of Windows's shortcomings to be unable to work with console programs easily. Please do not compensate for this in your code and upset everyone who's found a way to do it.
Another option is creating a batch file that calls your executable and then does pause.
Related
I want the following assembly to write Hello World! in the current console. Currently it is working but writes Hello World! into a new console window. I have tried removing the invoke AllocConsole statement but it does not write anything and exits with code -1073741819. What is the simplest way to use the existing console window when the executable is called from the terminal?
include 'win64ax.inc'
.data
tex TCHAR 'Hello World!'
dummy rd 1
.code
start:
; Don't want to allocate new console. How to use existing??
invoke AllocConsole
invoke WriteConsole, <invoke GetStdHandle, STD_OUTPUT_HANDLE>, tex, 12, dummy, 0
invoke Sleep, 1000
.end start
I don't have a great way to word this question's title. But I think I can explain what i'm asking for quite clearly.
The title of the question is, How can I make a ruby program that sends to stdout in real time like copy does?
I'll explain what I mean.
Suppose in one command prompt I do
C:\Windows\System32>md e:\exes
C:\Windows\System32>copy *.exe e:\exes >c:\carp\f.f
C:\Windows\System32>
Then from another command prompt I do
C:\carp>type f.f
I then see the f.f file build up, as the copy progresses.
and once the copy is complete, then f.f has the full stdout
However, this is not the case with my ruby program
Here is my ruby program
E:\rubylig>type putsandoutput.rb
20.times do
puts "a"
sleep 1
end
E:\rubylig>ruby putsandoutput.rb >a.a
If I then open another cmd prompt and do
E:\rubylog>type a.a
The a.a file is blank, until the putsandoutput.rb program has run to completion.
Then the a.a file is full.
But i'd like my ruby program to, like copy, be able to have its output redirected to the file, as it runs, rather than waiting till it completes.
Is it possible to do that. If so how, and if not then why not?
If not then i'm guessing it's a limitation of Ruby..
It's not a command line limitation, since 'copy' can do it.
You may be asking how to "flush" stdout. I thought that puts would flush automatically, so maybe it does not. Try $stdout.flush.
How can I create a macro (for instance LibreOffice calc) that runs a bash script in terminal (for instance xfce4-terminal). An example:
#!/bin/bash
echo "Hello world"
echo "Press any key to close this window"
read
I tried the Shell command in macro editor, but nothing happened. Here is what I did:
Sub testMysql
Shell ("/mnt/save/janos/home/testbashsql",4)
end Sub
It compiles and runs without error, but no output. As a side question: what does "compile" mean in this context, i.e. what happens to the compiled code? where is it stored? Why is there a "compile" button?
Thanks for helping me better understand macros.
Calling the script will execute the script in a shell. To see results, the script should write to a file rather than stdout, because LibreOffice does not display stdout.
To open a terminal instead, call the terminal. This worked on my system.
Shell("xterm")
Regarding the compile button in the LO IDE, I use it to check Basic code for any syntax errors. I am not aware of any compiled stored code. Documentation is at https://help.libreoffice.org/Basic/Compile.
I want to get the exit code of my tutorial assembly program (using masm32 and link). It was working fine, I would type echo %errorlevel% and it would display my exit code that I typed in after invoke ExitProcess. Now it doesn't work anymore. I'm using VirtualBox on an OpenSuse 12.1 host and Windows Vista Home Premium as the guest. I've searched for answers but have come up short. Most complaints are about using a batch file, which is not what I'm trying to do. Here is the simple program
hello_world.asm
.586
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
HelloWorld db "Hello World!", 0
.code
start:
invoke MessageBox, NULL, addr HelloWorld, addr HelloWorld, MB_OK
invoke ExitProcess, 2
end start
I expect it to return 2, but echo %errorlevel% returns 0. Is there something I'm missing? Thanks, and I apologize this question has been answered to death. I just can't find my answer.
Edit: Actually, I found part of my answer. It only works if I link using /SUBSYSTEM:CONSOLE. Using /SUBSYSTEM:WINDOWS always returns 0. I don't know what to make of this. where is the exit code with a windows program? any info greatly appreciated.
If your subsystem is Windows, then the command processor returns to the command prompt immediately without waiting for the program to exit. (Try it with notepad for example.) Since time travel has not yet been invented, it cannot tell you what the exit code of the program is, since the program hasn't exited yet.
Launch the process like this:
start /wait helloworld
That will make the command shell wait until the process has finished, so that it can retrieve the exit code.
(You don't need to do this if you are using a batch file.)
Many of you may recall the old DOS program--debug. Though outdated in many respects, one of the nice things about it was that one could easily find the byte-sequence for a given instruction without having to go through the steps of writing a program, compiling, disassembling, examining the file contents, .... Enter the instruction, then dump the instruction address. 'debug' regrettably does not do 32 bit instructions.
Does anyone know of a tool that does something similar for 32-bit x86 instructions? I don't want to go through the whole compile process; I just need to be able to enter a couple of instructions and have it spew out the length of the instruction and its byte sequence.
DOS debug was an interactive assembler as well as a debugger, entering assembly code resulted in that line being converted immediately to machine code - which is what you dumped out.
So all you need is to automate your favourite assembler with a script or batch-file.
Here's a bash function I came up with in a minute or two using the popular nasm assembler:
opcode() {
echo $* > tmp.S && nasm tmp.S -o tmp.o && od -x tmp.o
rm -f tmp.o tmp.S
}
Takes less than a second. Invocation looks like this:
$ opcode mov eax, [ebx]
0000000 6667 038b
0000004
$ opcode fadd st0,st1
0000000 c1d8
0000002
Not brilliant, but you can tweak od command-line for better output. This idea should work with any command-line assembler as long as you tell it to use a simple binary output format.
There are a few simple, 32-bit command line debuggers to be found. Based on your description, OllyDbg might fit your needs well. At least some versions of Microsoft's Debugging Tools for Windows include one named CDB, which stands for Commandline DeBugger (though I haven't verified that the linked version includes it...)