0

我有一个在命令行上运行的程序。我称之为:myexe.exe 参数。现在我想向我的命令行输出一条消息(例如成功或错误)

我试过了:

   return('there is an error')   --> noting is displayed
   Halt(0,'there is an error')   --> a Windows-message is displayed

如何输出消息或其他数据?

4

1 回答 1

1

这是一个使用 AttachConsole、GetStdHandle 和 WriteConsoleA的示例,特别是从 Clarion GUI 应用程序类型而不是像其他示例中的 CUI 执行此操作。

  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
于 2018-03-16T10:20:30.473 回答