Returning string value from clarion-built executable to powershell script

Hi Folks,


  1. I have an executable built in clarion that retrieves some data.
  2. The executable is called from a powershell script.
  3. The executable is a single window procedure.
  4. I would like to return a string value to the powershell script (rather than saving to disk, need to stay off-disk if possible).
  5. Window procedure has a return value set to a string variable.
  6. Return value is set correctly on closing the window.
  7. Powershell script will not recognise the return value.

Now either my powershell script isn’t picking up the return value (I’ve gone through a whole bunch of iterations),

Or for some reason the executable is not returning anything (this seems more likely).

This could be because I’ve missed something in telling it what to return.

Any thoughts on what I might have missed / be doing wrong - Or if this is possible.



AFAIK a Windows Exe can only return an Integer using SetExitCode(int) which in PS is accessed as $LastExitCode or BAT ErrorLevel

You could put a String value on the Clipboard and set an Exit Code to indicate success. Other ways would be Interprocess communication

1 Like

Right, the clipboard. Good stuff, thanks Carl!

That’ll probably be my solution until we figure out something deeper (like interprocess comms).

Or perhaps an environment variable?

1 Like

Cheers Jeff, that’s a good point. Will investigate.

Not saying it’s a perfect solution, but there it is… :slight_smile:

Your exe should put the result into stdout.


Brahn’s Console class has the code to write to StdOut. Don’t forget the Exp file MUST have CUI in it, but you said you had a Window so that would Not be CUI console mode.


For ‘something deeper’ you could use PowerShells DLLImport to call a Clarion procedure in a DLL in the same way it can call a Windows API procedure.
The procedure would need to use compatible datatypes and be tagged as PASCAL etc etc

Using DLLImport in that way you should be able to pass values both ways - untested but I don’t see why it shouldn’t work.


Very nice. I’ll have to give this a look-see.

I like Grahams idea, you could write it as a powershell cmdlet
note cmdlets return objects not simple strings

1 Like

Thanks Mark, appreciated.