Posts: 88
Threads: 33
Joined: Feb 2007
Purpose: I have created an executable which is run via DOS prompt in Windows. Is there a command to "echo" text onto the prompt, similar to Windows .bat files ?
Also, the exe does not wait for the functions within it to exit. The exe returns almost immediately and functions keep performing.
And how is it possible to exit the program with errorcode (Failed Status) ?
Posts: 12,071
Threads: 140
Joined: Dec 2002
Macro
if(!AttachConsole(ATTACH_PARENT_PROCESS)) ErrMsg 1 _s.dllerror ;;note: this fails if the exe is not running from cmd.exe (DOS prompt)
;using C console functions
_cputs "[]Qm exe here.[]" ;;simple string
str s.time("%X")
_cprintf "Now is %s[]" s ;;formatted like out
;using Windows console functions
int hStdout=GetStdHandle(STD_OUTPUT_HANDLE)
SetConsoleTextAttribute hStdout FOREGROUND_GREEN
s.format("Press Enter to continue.[]")
WriteFile hStdout s s.len &_i 0
SetConsoleTextAttribute hStdout FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE ;;white
;if exe launches other threads, it must wait until they'll end
;because if exe ends immediately, it terminates these threads
ARRAY(int) threads
threads[]=mac("Function64") ;;launch second thread
threads[]=mac("Function67") ;;launch third thread
WaitForMultipleObjects threads.len &threads[0] 1 INFINITE
;all threads can use _cprintf etc too
ret 400 ;;exit code
AttachConsole is unavailable on win 2000.
Posts: 12,071
Threads: 140
Joined: Dec 2002
Function
WaitForThreads
;/
function $thread1 [$thread2] [$thread3] [$thread4] [$thread5] [$thread6] [$thread7] [$thread8] [$thread9] [$thread10]
;Waits until all specified threads will end.
;EXAMPLE
;mac "Function64"
;mac "Function67"
;WaitForThreads "Function64" "Function67"
0.1
opt waitmsg -1
int i nt(getopt(nargs))
lpstr* t=&thread1
QMTHREAD q
rep
,for(i 0 nt) if(EnumQmThreads(&q 1 0 t[i])) break
,if(i=nt) break
,wait 0 H q.threadhandle