我有一个在命令行上运行的程序。 我把它称为:myexe.exe参数。 现在我想向命令行输出一条消息(例如成功或错误)
我试过了:
return('there is an error') --> noting is displayed
Halt(0,'there is an error') --> a Windows-message is displayed
如何输出信息或其他一些数据?
答案 0 :(得分:1)
这是一个使用AttachConsole,GetStdHandle和WriteConsoleA的example,特别是使用Clarion GUI apptype而不是CUI,就像使用其他example一样。
PROGRAM
HANDLE EQUATE(UNSIGNED)
DWORD EQUATE(ULONG)
BOOL EQUATE(BYTE)
VOID EQUATE(LONG)
LPVOID EQUATE(ULONG)
LPDWORD EQUATE(ULONG)
ATTACH_PARENT_PROCESS EQUATE(-1)
STD_OUTPUT_HANDLE EQUATE(-11)
MAP
MODULE('API')
AttachConsole(DWORD dwProcessId),BYTE,PASCAL,RAW
FreeConsole(),BYTE,PROC,PASCAL,RAW
GetStdHandle(DWORD nStdHandle),LONG,PASCAL,RAW
WriteConsoleA( |
HANDLE hConsoleOutput, |
VOID lpBuffer, |
DWORD nNumberOfCharsToWrite, |
*LPDWORD lpNumberOfCharsWritten, |
LPVOID lpReserved),BYTE,PASCAL,RAW,PROC
END
WriteLine PROCEDURE(STRING pMessage)
END
Window WINDOW('Test WriteConsole'),AT(,,101,43),GRAY,FONT('Microsoft Sans Serif',8)
BUTTON('Write To Stdout'),AT(17,12),USE(?ButtonTest)
END
CODE
Open(Window)
ACCEPT
IF Event() = EVENT:Accepted AND Accepted() = ?ButtonTest
WriteLine('Hi!')
END
END
WriteLine PROCEDURE(STRING pMessage)
conHandle HANDLE
outLen LPDWORD
bufferStr &CSTRING
CODE
bufferStr &= New(CSTRING(Len(pMessage)+2))
bufferStr = pMessage & '<10><0>'
IF AttachConsole(ATTACH_PARENT_PROCESS)
conHandle = GetStdHandle(STD_OUTPUT_HANDLE)
WriteConsoleA(conHandle,Address(bufferStr),LEN(bufferStr),outLen,0)
FreeConsole()
END
Dispose(bufferStr)
RETURN