Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
writing a string to standard out
#1
How can I do this? or how can I have the output of out() going to standard out? thanks.
#2
How do you create or get standard out in QM?
#3
I actually don't know how and was asking a question of how can it be done. Thanks.
#4
Standard out is used in console programs. They use printf and similar functions. QM is not console program and does not have standard out.

I thought maybe you have exe that should write to stdout of command prompt or some other console process that launched it.

Or maybe you want to write to dbgview.exe? Then use OutputDebugString.
#5
Yes, after reading up briefly on DbgView.exe I think using OutputDebugString should work for my purpose. What is the syntax for using it within QM? thanks.
#6
Function outd
Code:
Copy      Help
;/
function ~text

;Outputs string that can be captured with dbgview.exe.
;You can find dbgview on the Internet.

;EXAMPLES
;outd "some text"
;outd 5
;outd 5.55
;int x(3) y(30)
;outd F"{x} {y}"
;outd _s.format("%i %i" x y)


if(empty(text)) text=" "
OutputDebugStringW @text
#7
I want to use my compiled exe (quickmacros.com/forum/viewtopic.php?p=27270) as command line application.

Therefore I search for a output to stdout (and maybe stderr too)

So instead of "msg arr[i]" I search for something like "_stdout arr[i]"

Is this supported somehow, or could this be taken as a feature request please?


Till now I found only this:
outd - dbgview.exe
out - QM output
msg - msgbox


Thanks in advance, Stefan.
#8
The latest QM beta has function ExeOutputWindow. I is not console stdout, it is a simple version of QM output pane to be used in exe where QM is unavailable.

If need standard console:
Function OutConsole
Code:
Copy      Help
;/
function $s

;In exe creates console window and writes string to standard output.

;EXAMPLE
;;/exe
;OutConsole "test"
;OutConsole "test"
;2


#if !EXE
out s
#else
int+ g_stdout
if !g_stdout
,lock
,if !g_stdout
,,AllocConsole
,,SetConsoleTitle "Test Console"
,,g_stdout=GetStdHandle(STD_OUTPUT_HANDLE)
,lock-

_s.from(s "[]")
WriteConsole g_stdout _s _s.len &_i 0
#9
.
Many thanks Gintaras,

but what should I do with this?

This flashes a new console window for a fractal of a second only.



I don't want to create a new console window!
If I call my exe from a console window, I just want print out the message to that console.

myMacro:
Code:
Copy      Help
;/exe


ARRAY(str) a
ParseCommandLine(_command a)

int i
str s
for i 0 a.len
    s.format( "%s" a[i] )
    OutConsole s


Usage:
Code:
Copy      Help
C:\>my.exe "huhu"
huhu

C:\>




In future, I want to take console input "_command ", manipulate the string, and write back to console window:
Code:
Copy      Help
C:\>my.exe path "C:\Temp\Test\file.ext"
C:\Temp\Test

C:\>
C:\>my.exe base  "C:\Temp\Test\file.ext"
file

C:\>


Is this possible with Quick Macros?
.
#10
Macro QM-console
Code:
Copy      Help
;/exe

;Run this to test MakeExe_Console, ConsoleOut and ConsoleIn.


ConsoleOut "Type something and press Enter"
str s
ConsoleIn s
ConsoleOut F"s=''{s}''"
1

;BEGIN PROJECT
;exe_file  $my qm$\QM-console.exe
;on_after  MakeExe_Console
;flags  6
;END PROJECT
Function MakeExe_Console
Code:
Copy      Help
;Converts QM-created exe from GUI to console.
;Use this function in 'Make exe' dialog, 'After' field.

;Example: <open>QM-console</open>.


str exe=_command
if(exe.endi(".qmm")) out "Function MakeExe_Console cannot be used with .qmm, must be .exe."; ret
_s="[3]" ;;IMAGE_OPTIONAL_HEADER::Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI
_s.setfile(exe 0x16c 1)
ret 1
Function ConsoleOut
Code:
Copy      Help
;/
function $s [flags] ;;flags: 1 stderr, 2 no newline

;In exe shows text in console window of this or parent process.

;s - the text.

;REMARKS
;Writes to the standard output buffer or error buffer (flag 1).
;Exe must be created as console. For it you need function MakeExe_Console. Put its name in 'Make exe' dialog, 'After' field.
;If exe runs from cmd.exe, can use its console. Else exe creates own console window when starting.
;If called in QM (not in exe), this function just calls out().

;Example: <open>QM-console</open>.


#if !EXE
out s
#else
int+ g_stdout g_stderr
if !g_stdout
,g_stdout=GetStdHandle(STD_OUTPUT_HANDLE)
,g_stderr=GetStdHandle(STD_ERROR_HANDLE)

int h=iif(flags&1 g_stderr g_stdout)
if(flags&2=0) s=_s.from(s "[]")

_s.unicode(s) ;;also need to set console font that supports Unicode characters, eg Lucida Console
WriteConsoleW h _s _s.len/2 &_i 0
Function ConsoleIn
Code:
Copy      Help
;/
function str&s

;In exe waits and reads user input text from console window.

;s - variable that receives the text (1 line).

;REMARKS
;Exe must be created as console. For it you need function MakeExe_Console. Put its name in 'Make exe' dialog, 'After' field.
;If exe runs from cmd.exe, can use its console. Else exe creates own console window when starting.
;If called in QM (not in exe), this function just calls inp().
;This function waits for Enter. While waiting, cannot process Windows messages and COM events. The thread should not have dialogs etc.

;Example: <open>QM-console</open>.


s.all
#if !EXE
if(!inp(s)) end "ConsoleIn failed, Cancel"
#else
int+ g_stdin
if !g_stdin
,g_stdin=GetStdHandle(STD_INPUT_HANDLE)

_s.all(16*1024 2)

if(!ReadConsole(g_stdin _s _s.len &_i 0)) end "ConsoleIn failed" 16
_s.fix(_i); _s.trim("[]")
if(_unicode) _s.ConvertEncoding(GetConsoleCP _unicode)
s=_s
#endif

;tested: _cgets fails.

Tested: printf and _cputs also work, but _cgets fails.
#11
Thank you very much.

I think I will need some time to play with this Big Grin


Great support! Happy that I bought it. Thanks again.
#12
In QM 2.4.1.5 added 'Console' option in 'Make exe' dialog, and functions ExeConsoleWrite, ExeConsoleRead, ExeConsoleRedirectQmOutput.

Download: http://www.quickmacros.com/download.html


Forum Jump:


Users browsing this thread: 11 Guest(s)